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.6 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-prompting-structured-output-builders
What is the main idea of "Structured Output: JSON and XML"?
Which concept is most central to "Structured Output: JSON and XML"?
What should a careful learner remember about "Many APIs have native JSON mode"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about JSON mode be treated?
Name one way to verify an AI answer about JSON mode.