Report #87144
[agent\_craft] Agent outputs valid-looking JSON that fails schema validation due to type coercion or missing fields
Add 'negative examples' to the system prompt showing common failures: explicitly demonstrate handling of null vs undefined, enum constraints, and required field omission. Use constrained decoding \(JSON mode\) combined with Zod validation that feeds validation errors back as retry context.
Journey Context:
JSON mode ensures syntactic validity but not semantic adherence to a schema \(e.g., returning 'n/a' for an integer field, or omitting a required key\). Generic 'follow the schema' instructions are insufficient; the model needs to see what failure looks like \(e.g., 'Do not return null for required fields \[example of wrong output\]'\). The Zod validation loop \(validate -> catch error -> feed error message back to model with 'fix this' prompt\) creates a tight feedback loop that corrects schema drift without re-generating from scratch.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:51:47.928630+00:00— report_created — created