Unit 7 ·

Structured output and self-checks

Read this first. Every question after it comes from these cards.

Learn · 1/3

Structured output

Your code can't read a friendly paragraph. It can read JSON.

When the answer goes into code or a spreadsheet, ask for JSON: software can read fixed fields reliably.

Give exact field names, types, formats, a rule for missing data (null) and 'no other text'.

A description of these fields is called a schema.

Schema

Return only JSON: {"vendor": string, "total": number, "due_date": "YYYY-MM-DD" or null}. No other text.

The whole lesson as text

Cards and key takeaways

JSON you can use, answers that check themselves.

Key takeaways

  • Ask for JSON with an exact schema and a rule for missing data.
  • Parse, check fields, keep a fallback.
  • Step by step for reasoning; critique and rewrite for quality.

Structured output

Your code can't read a friendly paragraph. It can read JSON.

When the answer goes into code or a spreadsheet, ask for JSON: software can read fixed fields reliably.

Give exact field names, types, formats, a rule for missing data (null) and 'no other text'.

A description of these fields is called a schema.

Schema

Return only JSON: {"vendor": string, "total": number, "due_date": "YYYY-MM-DD" or null}. No other text.

Remember: Ask for JSON with an exact schema and a rule for missing data.

Still check it

Asked for JSON? Don't assume you got it.

Models usually follow the format, but not always.

Your code should parse the result, check the fields and have a fallback.

Many APIs also offer a strict structured-output mode.

Remember: Parse, check fields, keep a fallback.

Reason, then check

For tricky answers, make the model show its work, then grade it.

For tricky calculations or decisions, ask the model to work step by step before giving a clearly marked final answer.

For quality, use a critique-and-rewrite loop: draft, a self-check against your criteria that lists problems, a rewrite that fixes only those, then your own review.

Remember: Step by step for reasoning; critique and rewrite for quality.

Try it now

Paste this into any AI assistant (ChatGPT, Claude, Gemini, Copilot). Fill in the parts in square brackets.

Extract the name, company and date from this text as JSON with the keys name, company, date (YYYY-MM-DD). Then check your JSON against the text and fix any mismatch. Text: [paste]

What to check in the answer: Valid JSON, exactly those keys, correct date format. A missing field should be null, not an invented value.

Want to go deeper?

This unit continues in a full course: AI-Powered Web & App Development (Vibe Coding). One of its lessons is free to try: “Writing effective code prompts”.