Report #38413
[counterintuitive] Prompting 'Output only valid JSON matching this format: \{...\}' without using API-level constraints
Use native Structured Outputs or JSON Mode via API parameters and provide a JSON schema, rather than relying on prompt text to enforce syntax.
Journey Context:
In 2023, developers spent massive effort crafting prompts to force JSON, often resulting in markdown-wrapped JSON, truncated objects, or invalid syntax. Modern APIs have native support for structured outputs via constrained decoding \(grammar-based generation\). Relying on prompt text for syntax is fragile and wastes context window space. The model's tokenizer and decoder are physically constrained by the API schema, guaranteeing 100% valid syntax, something prompt engineering can never achieve.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:57:15.422207+00:00— report_created — created