Skip to main content
Validate task output with guardrails — failed checks retry automatically with feedback about what to fix. To enforce a typed contract instead of custom checks, use Structured Outputs; parse failures now surface via TaskResult.error.
The retry-with-feedback prompt wiring described below (upstream output + guardrail feedback injected into the next attempt’s prompt) requires a praisonaiagents build from 2026-07-28 or later (see upstream fixes 36da000 and de5a95d). On earlier builds task.validation_feedback was populated on the Task object, but the retry attempt’s LLM prompt was assembled without it — the retry ran with the same original prompt as attempt 1.
Decision routing is case- and whitespace-insensitive as of the praisonaiagents build merging MervinPraison/PraisonAI#4260 (2026-08-23). On earlier builds a verdict with a trailing newline — "invalid\n", which is what LLMs routinely return — missed the condition lookup and the workflow finished silently as though everything passed: the task was not retried, validation_feedback was not populated, and no exception was raised. Upgrade if your judge task’s condition keys are not matching what the model returns.
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:

How the router reads your verdict

The Process router applies .lower().strip() to the model’s decision before looking it up in condition, so case and surrounding whitespace never break a match.
These model outputs all route to the invalid branch:
An unmatched decision and a deliberate exit take the same branch — no exception, no warning. "Invalid." (trailing punctuation), "not valid" (paraphrase), or any verdict absent from condition falls through to the exit branch and the workflow finishes silently. To stay on the routed path:
  • Keep condition keys lowercase, whitespace-free, and punctuation-free.
  • Instruct the judge agent to reply with exactly one allowed verdict — "Reply with exactly one word: valid or invalid."
  • Add a key for every verdict you expect the judge to return.
Detect a silent miss by watching for the log line Workflow exit condition met on decision: <key> when you expected a retry.

Which verdicts trigger validation feedback

Only a closed set of verdicts populate task.validation_feedback when routed back to a previous task — Process.VALIDATION_FAILURE_DECISIONS in praisonaiagents/process/process.py is the source of truth:
A verdict outside this list (for example "revise") can still route to a retry task via condition, but it will not populate validation_feedback with the judge’s reasoning. Use one of the listed verdicts as your retry key when you want the feedback dict populated.

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 Under the hood the workflow process engine writes the feedback and any upstream output onto task._execution_context. The prompt builder folds this field into the retry attempt’s context. The field is deliberately preserved across the run_task/arun_task retry loop and reset by the Process engine before the next task is selected, so retries within the same attempt see the feedback and there is no cross-task leak.
When a whole-task guardrail rejects an AgentTeam task, the re-run now populates Task.validation_feedback and Process._build_task_context renders it into the retry’s prompt — the same slot that decision-based validation has always filled. The re-run is no longer a blind repeat of the identical prompt.
Since PraisonAI #4929, AgentTeam re-runs fill Task.validation_feedback from the guardrail reason. Earlier releases logged the reason and dropped it before the re-run, so the second attempt saw the same prompt as the first with no clue about what to fix.
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