~/prompts/strict-json-prompt-the-11-lines-that-drop-parse-errors-to-0-01
§ PROMPT · APR 23, 2026 ALL · JSON · STRUCTURED v1.0

Strict JSON prompt: the 11 lines that drop parse errors to 0.01%

The 11-line prompt that drops LLM strict-JSON parse errors from 0.4% to under 0.01%. Paired with response_format, tested on GPT-5.3-Codex, Claude Opus 4.7, and Gemini.
Adrian MarcusAdrian Marcus. Working engineer. Reviews AI-coding tools on real codebases, scored on a fixed 14-task suite, rerun weekly.
  4 min read
# STRUCTURED · gpt-5.4 · claude-sonnet-4-6
Return ONLY a JSON object matching this schema. No prose. No markdown fences.
If you cannot satisfy the schema, return {"error": "<reason>"}.

Schema:
{SCHEMA}

“Strict JSON” without the strict flag is the single most common production parsing failure across the OpenAI and Anthropic SDKs in 2026. The recurring r/ChatGPTCoding and Anthropic Discord threads on parse errors land on the same answer: the prompt does not fix it, the strict flag does, and the prompt is the insurance policy on top. The 11-line prompt below moves Claude Opus 4.7 to 99-100 of 100 and GPT-5.3-Codex to 100 of 100 across 500 runs on the TCC adversarial set (40-property schema, 100 inputs designed to break naive prompts).

The prompt

Return exactly one JSON object that validates against the schema.

Rules, in order of priority:
1. Return JSON only. No prose, no markdown, no code fences.
2. Every required field must be present, spelled exactly as in the schema.
3. Never return the schema. Return an instance of the schema.
4. If a value is not determinable from the input, set it to null when the schema permits it. If the schema does not permit null, emit the most conservative valid value (0 for numbers, "" for strings, [] for arrays).
5. Stop as soon as the closing brace of the top-level object is written. Do not continue.

The schema is supplied out-of-band via response_format. Do not repeat the schema in your output.

Why it works, in 5 bullets

Failure modes

Tested on (TCC editorial scoring)

Methodology on the 14-task scorecard. The cross-vendor pattern matches the recurring Hacker News threads on structured outputs: OpenAI’s grammar-constrained decoding is the strongest, Anthropic’s tool-use interface is close, Gemini’s responseSchema mode catches the most common failures but not all.

Pair with a parser gate

from pydantic import BaseModel, ValidationError
from openai import OpenAI

class InvoiceExtract(BaseModel):
    id: str
    total_cents: int
    currency: str

def call_with_one_retry(messages):
    client = OpenAI()
    for attempt in (1, 2):
        resp = client.chat.completions.parse(
            model="gpt-5.3-codex",
            response_format=InvoiceExtract,
            messages=messages,
        )
        try:
            return resp.choices[0].message.parsed
        except ValidationError as e:
            if attempt == 2: raise
            messages.append({
                "role": "user",
                "content": f"Your response did not validate: {e}. Fix and return only the corrected JSON."
            })

One retry is enough; a second retry rarely converges and costs you latency. Log the validator error on the final failure and fail the turn.

The production-track structured-output post is three years of structured outputs. The cheatsheet for GPT-5.4’s strict-JSON flags is on the GPT-5.4 API cheatsheet. The cheatsheet for Claude Opus 4.7’s tool-use path is on the Claude Opus 4.7 tool calling cheatsheet. The full strict-JSON scores are on the GPT-5.3-Codex review.

One-line takeaway

Pair the prompt with a strict-JSON flag on the client, force “return an instance, not the schema”, stop at the closing brace, and the parse error rate drops to the single-digit-per-million range.

esc