Advanced Patterns
ReAct, self-critique, and strict structured output.
- ✓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
| 1 | |
| 2 | |
| 3 | |
Production pipelines rely on strict JSON output so the model's response can flow straight into other software.
- • Asking for JSON but allowing prose, so the output cannot be parsed reliably.
Write a prompt that returns a product review as strict JSON with keys 'summary' and 'rating' (1-5).
1. The ReAct pattern combines...
2. Why request strict JSON output?