Report #84549
[counterintuitive] Writing 'Output ONLY valid JSON matching this schema' in the system prompt to get structured data
Use native Structured Outputs / Tool Use APIs \(e.g., OpenAI's response\_format with json\_schema, Anthropic's tool\_choice\) to constrain decoding.
Journey Context:
Prompting for JSON was notoriously brittle, leading to markdown-wrapped JSON, missing commas, or schema violations, requiring complex regex parsing and retry loops. Native structured outputs constrain the decoding process at the token level, guaranteeing 100% schema adherence. Prompting for JSON is now an anti-pattern unless the API lacks native support, as it wastes prompt tokens and compute on a problem solved deterministically at the inference layer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:30:09.337889+00:00— report_created — created