Critics are the core of Sifaka’s text improvement system. They analyze text and provide structured feedback for iterative refinement.
Each critic implements a specific evaluation strategy based on academic research:
Critic | Best For | Research Paper | |
---|---|---|---|
SELF_REFINE | General improvement | Self-Refine (2023) | |
REFLEXION | Learning from mistakes | Reflexion (2023) | |
CONSTITUTIONAL | Safety & principles | Constitutional AI (2022) | |
SELF_CONSISTENCY | Balanced perspectives | Self-Consistency (2022) | |
SELF_RAG | Fact-checking | Self-RAG (2023) | |
META_REWARDING | Self-evaluation | Meta-Rewarding (2024) | |
N_CRITICS | Multiple perspectives | Based on ensemble methods | N-Critics (2023) |
STYLE | Tone & style | Custom implementation |
from sifaka import improve
from sifaka.core.types import CriticType
result = await improve(
"Your text here",
critics=[CriticType.SELF_REFINE]
)
result = await improve(
"Your text here",
critics=[CriticType.SELF_REFINE, CriticType.REFLEXION]
)
from sifaka.core.config import Config, CriticConfig
config = Config(
critic=CriticConfig(
critics=[CriticType.CONSTITUTIONAL],
confidence_threshold=0.8
)
)
result = await improve("Your text", config=config)
General-purpose improvement focusing on clarity, coherence, and completeness.
Use when:
Example:
result = await improve(
"AI is important for business.",
critics=[CriticType.SELF_REFINE],
max_iterations=3
)
Learns from previous attempts by reflecting on what worked and what didn’t.
Use when:
Example:
result = await improve(
"Explain quantum computing simply.",
critics=[CriticType.REFLEXION],
max_iterations=4 # Benefits from more iterations
)
Evaluates text against constitutional principles for safety and ethics.
Use when:
Principles evaluated:
Example:
result = await improve(
"Guide on pest control methods",
critics=[CriticType.CONSTITUTIONAL]
)
Generates multiple perspectives and finds consensus.
Use when:
Example:
result = await improve(
"Analysis of renewable energy policies",
critics=[CriticType.SELF_CONSISTENCY]
)
Fact-checks and retrieves information to verify claims.
Use when:
Requires tools:
# Tools must be configured separately
result = await improve(
"The Great Wall of China facts",
critics=[CriticType.SELF_RAG]
)
Evaluates its own critique quality through meta-evaluation.
Use when:
Example:
result = await improve(
"Medical advice disclaimer",
critics=[CriticType.META_REWARDING]
)
Uses multiple critical perspectives in parallel.
Use when:
Default perspectives:
Example:
result = await improve(
"Product launch announcement",
critics=[CriticType.N_CRITICS]
)
Transforms text style and tone.
Use when:
Configuration:
from sifaka.critics.style import StyleCritic
critic = StyleCritic(
style_description="Casual and friendly",
style_examples=[
"Hey there! Let me explain...",
"No worries, we've got you covered!"
]
)
Critics work well together:
# Technical accuracy + readability
result = await improve(
text,
critics=[CriticType.REFLEXION, CriticType.STYLE]
)
# Safety + factual accuracy
result = await improve(
text,
critics=[CriticType.CONSTITUTIONAL, CriticType.SELF_RAG]
)
# Comprehensive review
result = await improve(
text,
critics=[
CriticType.SELF_REFINE,
CriticType.N_CRITICS,
CriticType.META_REWARDING
]
)
Fast critics:
Thorough critics:
Resource intensive:
Create your own critic:
from sifaka.plugins import CriticPlugin
from sifaka.core.models import CritiqueResult
class DomainExpertCritic(CriticPlugin):
def __init__(self, domain: str):
self.domain = domain
async def critique(self, text: str, result):
# Your critique logic
feedback = f"From a {self.domain} perspective..."
return CritiqueResult(
critic=f"domain_expert_{self.domain}",
feedback=feedback,
suggestions=["Add more domain-specific details"],
needs_improvement=True,
confidence=0.75
)
# Use it
result = await improve(
text,
critics=[DomainExpertCritic("medical")]
)
Text not improving?
Too many changes?
Inconsistent results?