Report #20881
[counterintuitive] Prompting for JSON or XML output with format instructions in the prompt text
Use native structured output features \(OpenAI structured outputs with json\_schema, Anthropic tool\_use with input\_schema\) instead of prompt-based formatting. Only fall back to prompt-based formatting for generative tasks where schema constraints reduce quality.
Journey Context:
Before native structured output, developers crafted elaborate prompts: 'respond in valid JSON with keys X, Y, Z. Do not include markdown fences.' This was fragile — models would add commentary, trailing commas, or wrap output in code blocks despite instructions. Native structured output constrains generation at the token level via constrained decoding, guaranteeing syntactically valid output that matches the schema. Prompt-based formatting also wastes tokens on format instructions that compete with content instructions for attention. The tradeoff: constrained decoding can slightly reduce model capability on open-ended generation because it restricts the token space. Use native structured output for extraction, classification, and API calls; consider unconstrained generation for creative or complex reasoning tasks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:27:35.573178+00:00— report_created — created