Loading lesson…
When your prompt feeds into code, you need machine-readable output. JSON mode and XML tags make the AI's response parseable instead of loose prose.
If you're using an AI inside an app, you don't want a friendly paragraph — you want data. A list of book titles. A calendar event with a date and duration. A code file and a test file. Structured output is how you get clean, predictable data the rest of your program can use.
Analyze this customer review and return ONLY valid JSON matching this schema:
{
"sentiment": "positive" | "neutral" | "negative",
"topics": string[],
"urgent": boolean,
"summary": string (max 20 words)
}
Do not include any text before or after the JSON.
Review: "Bought this for my grandma. The setup was a nightmare — the instructions are in tiny print and missing page 3. But once my son helped her get it working, she loves it. Still, I'd return it if I could."A typical JSON extraction prompt.The AI will return a JSON object like {"sentiment": "negative", "topics": ["setup", "instructions", "accessibility"], "urgent": false, "summary": "Setup was frustrating but grandma loves the product."}. Your code can JSON.parse it and move on.
Anthropic's Claude was trained with lots of XML-tagged data, so it responds very well to XML tags for structure. You can both send and request them.
I'll give you a support email. Extract information and wrap your answer in XML tags.
<email>
Subject: Broken laptop
Hi, my laptop won't turn on. I ordered it 3 weeks ago, order #A8823. I'm out of town until Friday. - Mike
</email>
Respond with:
<customer_name>...</customer_name>
<order_id>...</order_id>
<issue>...</issue>
<urgency>low | medium | high</urgency>
<suggested_reply>...</suggested_reply>XML tags separate input from output and make fields easy to parse.| JSON | XML Tags |
|---|---|
| Best for data going into code. | Best for long content with multiple sections. |
| Compact, widely supported. | More readable for humans, flexible for mixed content. |
| Brittle — one stray comma breaks it. | Forgiving — ignores stray text outside tags. |
| Ideal: extractions, classifications, small objects. | Ideal: essays with sections, multi-step reasoning, document analysis. |
You are a calendar assistant. Extract events and return ONLY JSON like:
[
{
"title": string,
"date": "YYYY-MM-DD",
"start_time": "HH:MM",
"duration_minutes": number,
"participants": string[]
}
]
Text:
"Team sync is Wednesday at 10am, 30 minutes, with Maya and Dev. Then I have yoga Thursday 6pm for an hour."Real extraction task — feeds right into a calendar app.15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-prompting-structured-output-builders
What is the core idea behind "Structured Output: JSON and XML"?
Which term best describes a foundational idea in "Structured Output: JSON and XML"?
A learner studying Structured Output: JSON and XML would need to understand which concept?
Which of these is directly relevant to Structured Output: JSON and XML?
What is the key insight about "Many APIs have native JSON mode" in the context of Structured Output: JSON and XML?
What is the key insight about "Validate the output" in the context of Structured Output: JSON and XML?
What is the recommended tip about "Level up your prompts" in the context of Structured Output: JSON and XML?
Which statement accurately describes an aspect of Structured Output: JSON and XML?
What does working with Structured Output: JSON and XML typically involve?
Which of the following is true about Structured Output: JSON and XML?
Which best describes the scope of "Structured Output: JSON and XML"?
Which section heading best belongs in a lesson about Structured Output: JSON and XML?
Which section heading best belongs in a lesson about Structured Output: JSON and XML?
Which section heading best belongs in a lesson about Structured Output: JSON and XML?
Which of the following is a concept covered in Structured Output: JSON and XML?