Skip to main content
Schema-validated handoffs ensure data integrity between agents using Pydantic models, raising validation errors immediately instead of producing incorrect LLM output.
The user receives polished content; the researcher hands off a schema-validated brief before the writer runs.

Quick Start

1

Define Schema + Create TypedHandoff

2

Execute with Validated Payload

3

Invalid Payload Raises Immediately


How It Works

StepDescription
ValidationPayload validated against Pydantic schema
SerializationValid payload converted to structured JSON
HandoffTarget agent receives formatted JSON context
Error HandlingSchema mismatches raise HandoffValidationError

Configuration

ParameterTypeDefaultDescription
agentAgentRequiredTarget agent to hand off to
input_schemaType[BaseModel]RequiredPydantic model class for validation
tool_name_overridestrNoneCustom tool name
tool_description_overridestrNoneCustom tool description
on_handoffCallableNoneCallback when handoff starts
input_filterCallableNoneFunction to filter input data
configHandoffConfigNoneAdvanced handoff configuration

Accepted Payload Types

Payload typeBehaviour
Instance of input_schemaRe-validated via model_dump()
dictValidated directly
Any Pydantic model with model_dump()Converted to dict, validated
Object with __dict__Vars extracted, validated
strBypasses validation — falls back to plain Handoff (backward compatibility)

Common Patterns

Research → Writer Pipeline

Customer Info Pipeline

Async Typed Handoffs

Combining with HandoffConfig

Receiving agent: input_payload_schema

Use input_payload_schema on the receiving agent to declare the Pydantic model it expects as incoming payload. This ensures that any agent sending data to this agent produces a payload that matches the declared schema — mismatches raise HandoffValidationError at the boundary.
When the sending agent calls TypedHandoff(agent=receiver, input_schema=DeployPayload).execute_programmatic(...) with an invalid payload, HandoffValidationError is raised:

Best Practices

Only include fields the receiving agent actually needs. Large schemas increase validation overhead and complexity.
Always catch HandoffValidationError at orchestration boundaries to handle schema mismatches gracefully:
Use e.validation_errors to surface field-level issues to users:
Use typed handoffs when passing more than 2 fields between agents. The validation cost is much lower than debugging wrong LLM output.
TypedHandoff requires Pydantic. Document the requirement:
Instantiating without Pydantic raises ImportError.

Handoffs

Plain handoffs (string payloads, no validation)

Handoff Filters

Filtering conversation history during handoffs

Handoff Config

Timeouts, retries, concurrency settings

Multi-Agent Patterns

Design patterns for agent collaboration