Report #52205
[agent\_craft] Structured output schema violations in zero-shot code generation
Provide 2-3 few-shot examples of the desired JSON/output format within the system prompt when generating structured data \(diffs, JSON patches, AST manipulations\), reducing schema violations by 40-60% compared to zero-shot with schema description alone.
Journey Context:
Zero-shot prompting with JSON schema descriptions works for simple objects, but for nested structures like unified diff format or tree-sitter queries, the model often omits required fields, uses wrong key casing, or injects markdown fences despite instructions. Empirical testing on code migration tasks shows that 2 examples \(positive examples only, no negative examples needed\) anchor the model's output distribution significantly better than detailed natural language descriptions. The examples should be minimal but complete, showing edge cases like empty arrays or null handling. This is distinct from few-shotting the task logic—here we few-shot the output syntax to constrain the parser.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:07:14.759579+00:00— report_created — created