Module 3 Lesson 4: The Critic and Validator Pattern
Self-improving AI. Using one model to generate and another to find the flaws.
Critic and Validator: The Quality Filter
The #1 problem with agents is that they are "Overconfident." If an agent generates something incorrect, it usually doesn't know it's incorrect.
The Critic and Validator pattern solves this by introducing a "Negative" persona whose sole job is to point out mistakes.
1. The Adversarial Concept
- The Generator: Creates the content (e.g., Code, Blog post).
- The Critic: Finds errors, gaps, and logical flaws.
- The Loop: The Generator must update the content based on the Critic's feedback until the Critic is satisfied.
This is exactly how Generative Adversarial Networks (GANs) work in classic AI, but applied to LLM reasoning.
2. Validator vs. Critic
- Critic (LLM): Qualitative feedback. "This tone is too aggressive."
- Validator (Code): Quantitative feedback. "The code failed the unit test." or "The JSON is missing the 'id' field."
A production agent system uses both.
3. Visualizing the Loop
graph LR
Draft[Generator: Create Draft] --> Critique[Critic: Find Flaws]
Critique --> Loop{Is it perfect?}
Loop -- No --> Draft
Loop -- Yes --> Final[Publish]
4. Why This Pattern is Essential
A. Reducing Hallucinations
Generators often hallucinate facts. Critics, when given a "Source document" (Module 10 RAG), are excellent at spotting when the Generator says something that isn't in the source.
B. Enforcing Style
If you are writing for a brand, a Critic can be programmed with the "Brand Voice Guide" and reject any text that uses forbidden words.
5. Code Example: The "Critique" Prompt
SYSTEM """
You are a Senior Editor. You are review the following text for:
1. Logical consistency.
2. Grammar errors.
3. Fulfillment of user requirements.
Provide a list of requested changes. If the text is perfect, write 'APPROVE'.
"""
USER """
[Generate Text Here]
"""
6. The "Consensus" Method
In high-stakes environments, you can use Multiple Critics.
- Critic 1 looks at Security.
- Critic 2 looks at Performance.
- Critic 3 looks at Readability. Only when all three say "APPROVE" is the task considered done.
Key Takeaways
- The Critic pattern creates a self-correcting feedback loop.
- It is easier for an LLM to spot a mistake than to avoid making it in the first place.
- Validators (scripts) are faster and cheaper for structural checks.
- This pattern is the key to achieving 99% accuracy in agentic systems.