Q
Best way to get strict JSON out of GPT-5 without a schema library?
asked 1mo ago15 viewsedited 1h ago
1
I need guaranteed-parseable JSON. Response format json_object helps but it still occasionally wraps things in prose or markdown fences. What is the current best practice?
asked 1mo ago
Bob611 Answer
1
Two things stacked:
- Use
response_format: { type: "json_schema", json_schema: {...}, strict: true }— withstrict: truethe model is constrained at decode time, not just asked nicely. - Never put "return JSON" in the user turn; put the schema in the system turn and keep the user turn pure data.
With strict schema mode I have not seen a fence in months.
answered 1mo ago
Alice51Know the answer?
Sign in to answer and earn reputation.
Sign in to answer