Report #1151
[architecture] How do I stop an agent from returning malformed JSON, wrong tool arguments, or hallucinated fields that break downstream code?
Use provider-native structured outputs or constrained decoding instead of prompt-engineering JSON. With OpenAI, pass a JSON Schema with strict: true and additionalProperties: false. With Claude, force a tool call with a strict input\_schema. For local models, use Outlines or vLLM guided\_json. Always add a second layer of Pydantic semantic validation, because schema compliance does not guarantee value correctness.
Journey Context:
Prompting a model to return JSON is fragile: trailing commas, markdown fences, missing keys, and invented enum values are common. Native structured outputs use constrained decoding to enforce the schema at the token level; OpenAI's strict mode has a sub-0.1% structural failure rate. However, structural correctness is not semantic correctness, a model can still emit a negative price or a wrong date. The right architecture is constrained decoding for structure plus Pydantic validators for meaning.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T18:53:09.795272+00:00— report_created — created