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.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:1. Guardrails (Recommended)
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:-
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
-
Creates typed validation outcome (recommended):
-
Passes feedback to retry task via context (legacy):
-
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 therun_task/arun_taskretry 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.
Typed Validation Outcome (Recommended)
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):Best Practices
Clear validation criteria
Clear validation criteria
Define specific, measurable criteria and return actionable feedback strings when validation fails. Include examples of valid output in task descriptions.
Efficient validation
Efficient validation
Use function guardrails for simple checks (length, format, required fields). Reserve LLM guardrails (string prompts) for subjective quality checks.
Set reasonable retry limits
Set reasonable retry limits
Use
max_retries=3 as a default. Increase only when feedback is precise enough for the agent to self-correct.Fail fast on structural errors
Fail fast on structural errors
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
Validation always fails
Validation always fails
- Check validation criteria are achievable
- Verify feedback is clear and actionable
- Test validation function separately
- Increase max_retries if needed
No feedback in retry
No feedback in retry
- Ensure using proper validation return format
- Check workflow connections
- Verify decision task conditions
- Enable verbose mode for debugging
Infinite validation loops
Infinite validation loops
- Set appropriate max_retries
- Implement retry counters
- Add fallback conditions
- Log validation attempts
Related
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

