IntermediateAbout 17 min

    Structured Outputs

    Read the full article on Substack

    7 min read.

    Make a model emit something a program can parse. Step the five layers from prompting to finetuning, watch a grammar mask the logit vector so an invalid token becomes unreachable rather than unlikely, and see how far LinkedIn's defensive parser carried them.

    Think of it this way: A form versus a blank sheet. Asking politely for an address gets you an address in whatever shape the writer felt like. A form with boxes gets you the same information in the same place every time — constrained sampling is the box, and everything above it is asking more politely.

    Two situations need structure, and they need it for different reasons. Everything else is formatting preference, which is worth much less engineering.

    Semantic parsing: text to SQL, text to regex, text to a config file, or classification where the answer must be one of a fixed set of labels. The structure is not packaging around the answer — it is the answer, and a near-miss is not a partial credit, it is a syntax error.

    text → SQL, text → regex, text → classification label

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    How strong is this guarantee?

    Sort

    Sort each technique by whether it can still return invalid JSON.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    Best effort — can still fail

    Drop items here

    Valid by construction

    Drop items here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    Which task inherently requires structured output rather than merely preferring it?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going