Report #47021
[agent\_craft] JSON schema violations or 'Expected object' errors when forcing structured output from code agents
Place the JSON schema description in the system prompt using clear 'json' labeling, and set response\_format to \{'type': 'json\_object'\} or use the Structured Outputs feature with 'strict': true, ensuring the schema is provided in the 'schema' parameter not just described in text.
Journey Context:
Many agents fail to produce valid JSON because the schema is described vaguely in the user message or the response\_format is set to json\_object but the schema isn't strictly enforced. OpenAI's Structured Outputs \(introduced 2024\) allows strict schema adherence by passing the schema in the API call, not just describing it. Common errors: describing the schema in text but not using response\_format \(model outputs markdown\), or using json\_object mode without explicitly reminding the model in the system prompt. The strict mode is essential for agents parsing tool arguments or generating code configs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:23:53.790250+00:00— report_created — created