StudyAIStudyAI
Pro
Lesson 610 minPro

Advanced Patterns

ReAct, self-critique, and strict structured output.

What you will learn
  • The ReAct (Reason + Act) pattern for tools
  • Self-critique to catch the model's own mistakes
  • Forcing strict JSON for reliable automation

Explanation

ReAct interleaves Reasoning and Actions: the model thinks, calls a tool, reads the result, then thinks again. It is the backbone of AI agents (covered in the Agents course).

Self-critique asks the model to review and improve its own draft ('List 3 weaknesses in the answer above, then rewrite it'). This often raises quality noticeably.

For automation, demand strict JSON so your code can parse the output. Specify the exact schema and add 'Respond with only valid JSON, no prose.'

Code Example

text
1
Respond with ONLY valid JSON in this schema:
2
{ "summary": string, "risk": "low" | "medium" | "high" }
3
No explanation, no markdown.
Real-world use

Production pipelines rely on strict JSON output so the model's response can flow straight into other software.

Common mistakes
  • Asking for JSON but allowing prose, so the output cannot be parsed reliably.
Practice

Write a prompt that returns a product review as strict JSON with keys 'summary' and 'rating' (1-5).

Knowledge check
0/2 answered

1. The ReAct pattern combines...

2. Why request strict JSON output?

Answer all questions to check.