Advanced prompting and structured output
Break big jobs into a chain of small prompts, get JSON and tables other tools can use, write reusable prompt templates, and make prompts that work across hundreds of inputs, not just one.
🎯 By the end of this lesson you will be able to:
- Split a complex task into a reliable chain of smaller prompts
- Ask for structured output, such as JSON, that software or spreadsheets can use directly
- Turn a good prompt into a reusable template and test it on many inputs
In this lesson
From one good chat to something you can rely on
Lesson 5 taught you to write a clear prompt for one task. At work you often need more: the same task done well for every ticket, every document or every customer message, sometimes as part of a tool your team built. A prompt that works once in a chat is not yet reliable. This lesson covers the techniques teams use to make AI work repeatably.
Prompt chaining: one job, several small steps
Asking a model to do five things in one prompt, such as read, analyse, decide, format and translate, increases the chance it skips or muddles a step. Prompt chaining splits the job into a sequence of smaller prompts, where the output of one becomes the input of the next. Each step is simpler, easier to check and easier to improve on its own.
Customer feedback, as a chain
Step 1 (extract): From this review, list each separate complaint or compliment as a short phrase. Step 2 (classify): For each phrase, label the product area (delivery, quality, price, support) and sentiment (positive or negative). Step 3 (summarise): From these labelled items for 200 reviews, write a one-page summary for the product team with the top three issues and their counts.
Each step does one thing. If labels are wrong, you fix step 2 only. Counting happens on clean labels instead of raw text, so the numbers are more trustworthy.
Structured output: answers software can use
Free text is great for people to read but hard for software to use. When the answer goes into a spreadsheet, a database, a ticket or another program, ask for a fixed structure: a table with named columns, CSV or, most often, JSON (a simple text format of names and values that almost every tool understands).
Asking for JSON
Read the support email below and return only JSON in exactly this shape:
{"category": "billing" | "technical" | "account" | "other", "urgency": "low" | "medium" | "high", "summary": string (max 20 words), "needs_human": true | false}
If a value is unclear, use "other" or false. Do not add any text outside the JSON.
<email>...</email>{"category": "billing", "urgency": "high", "summary": "Customer charged twice for March subscription and wants refund", "needs_human": true}
Listing the allowed values for each field makes results consistent. Many AI platforms can also enforce a JSON schema so the model cannot return the wrong shape.
Reusable prompt templates
When a prompt works, turn it into a template: fixed instructions with clearly marked slots for the parts that change, such as {{user_story}} or {{release_notes}}. Templates make results consistent across a team, and they are how prompts are stored inside AI-powered applications. Keep templates in a shared place, give them owners and version numbers, and record what changed and why.
| Part of a template | Example |
|---|---|
| Stable instructions | You are a QA analyst. Write test cases for the user story below… |
| Variables | {{user_story}}, {{acceptance_criteria}}, {{platform}} |
| Output format | Return a table: ID, scenario, steps, expected result |
| Guard rails | If the story is unclear, list questions instead of guessing |
Making prompts robust
- Test on many inputs, not one. Collect 20 to 50 real examples, including messy, short, long and unusual ones, and check the results for all of them.
- Show what not to do. A short negative example ("Do not write: …") often fixes a recurring mistake.
- Give an escape route. Tell the model what to return when the input doesn't fit, such as "unknown" or a question back, so it doesn't invent an answer.
- Ask for a self-check on important work. After the draft, ask the model to check it against your requirements and list any gaps, then review that list yourself.
- Change one thing at a time and re-run your examples, so you know what actually helped.
What this means for your role
Developer
Store prompts as versioned templates in code, ask for JSON with a schema, validate every response, and add automated tests that run your prompt set on each change.
Tester / QA
A prompt is now part of the product. Build a fixed set of test inputs for each template and re-run it whenever the prompt or model changes, comparing results side by side.
Business Analyst / PO
Specify AI outputs as structures: fields, allowed values and what happens when information is missing. This is far easier to test than "a good summary".
Tech Lead / Architect
Treat prompts like configuration: owned, reviewed, versioned and rolled back when needed. Prefer chains of simple steps over one giant prompt for anything important.
Project / Delivery Manager
Ask how a prompt was tested, on how many examples, and what the failure rate was, before a team relies on it in a process customers see.
Scrum Master / Agile
Create a shared, owned prompt library for the team, and review useful additions in retrospectives so good practice spreads.
Try it: build a two-step chain with JSON
- Take five real items from your work, such as tickets, emails or user stories (with personal data removed).
- Step 1: ask the AI to return JSON for each one with three fields you choose, listing allowed values.
- Step 2: paste the five JSON results back and ask for a short summary table. Note where the JSON was wrong and improve step 1.
Key takeaways
- Prompt chains split big jobs into small, checkable steps.
- Ask for structured output with allowed values, and always validate it.
- Turn working prompts into versioned, shared templates with clear variables.
- Robust prompts are tested on many real inputs, include an escape route, and change one thing at a time.
Key terms
- Prompt chaining
- Splitting a task into a sequence of prompts where each step's output feeds the next.
- JSON
- A simple text format of names and values that software can read reliably.
- Prompt template
- A reusable prompt with fixed instructions and variable slots.
- System prompt
- Standing instructions that apply to every message in an AI application or conversation.
Check your understanding
Answer all 5 questions. Score 3 or more to complete the lesson.
1. Why split a complex task into a prompt chain?
2. What is the main reason to ask for JSON output?
3. What should software do with an AI's JSON output?
4. How should you check a new prompt template is reliable?
5. What is an "escape route" in a prompt?