Skip to main content
Validate task output with guardrails — failed checks retry automatically with feedback about what to fix.
The user asks for output that must meet a guardrail; failed validation sends feedback into the next retry until the check passes or retries are exhausted.

How It Works

Quick Start

1

Install Package

First, install the PraisonAI Agents package:
2

Create Validation with Guardrails

The simplest way to add validation is using guardrails:

Validation Methods

PraisonAI offers two primary validation approaches: Guardrails provide inline validation with automatic retry and feedback mechanisms.

Function-Based Guardrails

LLM-Based Guardrails

For complex validation that requires understanding:

2. Decision-Based Validation Workflows

For complex validation flows with multiple validators:

How Validation Feedback Works

When validation fails, the system automatically:
  1. Captures the validation feedback including:
    • The validation decision (e.g., “retry”, “invalid”)
    • Detailed feedback about what was wrong
    • The original output that failed
    • Which validator made the decision
  2. Creates typed validation outcome (recommended):
  3. Passes feedback to retry task via context (legacy):
  4. Includes feedback in task context for the next attempt
Decision tasks expose task.validation_feedback (dict) with retry details. Use it in the next attempt’s prompt or handler.
Use the typed outcome for robust error handling:

Complete Examples

Example 1: Data Validation Pipeline

Example 2: Multi-Stage Validation

Example 3: Complex Validation with Context

Validation Feedback in Action

When validation fails, agents receive both typed outcomes and legacy feedback: Typed Outcome (Recommended):
Legacy Dict Format (Backward Compatibility):

Best Practices

Define specific, measurable criteria and return actionable feedback strings when validation fails. Include examples of valid output in task descriptions.
Use function guardrails for simple checks (length, format, required fields). Reserve LLM guardrails (string prompts) for subjective quality checks.
Use max_retries=3 as a default. Increase only when feedback is precise enough for the agent to self-correct.
Validate JSON schema, required sections, or word counts before expensive downstream tasks run.

Advanced Configuration

Retry Strategies

Custom Feedback Formatting

Common Validation Patterns

Word/Character Count

Content Requirements

Troubleshooting

  • Check validation criteria are achievable
  • Verify feedback is clear and actionable
  • Test validation function separately
  • Increase max_retries if needed
  • Ensure using proper validation return format
  • Check workflow connections
  • Verify decision task conditions
  • Enable verbose mode for debugging
  • Set appropriate max_retries
  • Implement retry counters
  • Add fallback conditions
  • Log validation attempts

Agent Run Outcomes

Typed validation outcomes and status handling

Guardrails

Deep dive into the guardrails system

Task Retry Policy

Per-task retry with exponential backoff

Workflows

Complex workflow patterns