Day 08·Control and verify·2 min read
Output control
Models follow structure well and exact counts poorly. Control output with schemas, examples and validation rather than instructions alone, and match the prompt's own shape to the shape you want back.
By the end
Enforce structure and length with schemas, examples and validation, and explain why a role prompt shifts style without adding facts.
Models follow structure well and exact counts poorly. So control output with schemas, examples and validation rather than with instructions alone.
Learn
- Structured output. Ask for JSON against a schema, or use the API's structured-output or tool-call mode. Validate every response and retry on failure.
- Prefilling. Some APIs let you start the model's reply, for example with an opening brace, which locks in the format.
- Length. State the limit, give examples at the target length, then check and regenerate. Max tokens only truncates.
- Audience and tone. Name the reader ("a curious 14-year-old", "a busy CFO"), the jargon rule, and the reading level. Plain-language example rewrites teach this fastest.
- Match the prompt to the output. A prompt written in heavy markdown tends to get markdown back. Plain prose tends to get prose.
- Role prompting. "You are a senior contracts lawyer" shifts vocabulary and focus, but it does not add real expertise or facts.
Drill
- Ask for a user record as JSON with
name(string, 32 characters max) andage(number, 16 or over). - Validate it in code (Zod, Pydantic or a JSON schema) and retry on any failure.
- Run 50 generations and record the failure rate with and without a schema mode.
Check yourself
- What are three ways to enforce a word limit beyond stating it?
- Why does a role prompt not fix factual errors?
Test yourself
6 multiple-choice questions and 7 flashcards on this lesson, shuffled every time, with the reason behind every answer.