Skip to content
anythingai.space
Prompting & Contextintermediate11 min · 8 steps

Structured Generation

Get JSON that always parses by constraining decoding at the engine, not by asking nicely, then validate the content and retry with the error.

WHAT CAME BACKSure, here is your JSON:{"name": "Ada","date": "March 5th"}Extractor“only return JSON”LLMJSON.parseSyntaxError
requesterrordatasignalresponsetool calltoken
1 / 8
ProblemStep 1 of 8

“Only return JSON” is a request, not a guarantee

The old way was to beg in the prompt: “Return only JSON, no other text.” Mostly it works. Sometimes the model adds a friendly preamble, a trailing comment, or a date in a format your code doesn't expect, and the parser throws.

A prompt depends on the model's willingness to comply, and at scale “mostly” means daily failures.

Lesson 6 of 8 in Prompting & Context