If you've built a multi-step agent workflow, you've probably seen this. Step one does its job and returns a nice paragraph. Step two reads that paragraph and does its job. It all works in testing. Then someone tweaks the first prompt, the paragraph comes out a little differently, and step two starts doing something slightly wrong. No error, no crash. Just quietly worse results.

The problem isn't the model. It's that the contract between your steps is prose, and prose has no shape you can check.

The fix is boring and it works: make each step return structured data, and validate it before the next step runs.

Here's what that looks like with Pydantic:

from typing import Literal from pydantic import BaseModel, ValidationError class TicketTriage(BaseModel): category: Literal["billing", "bug", "how_to", "other"] priority: Literal["low", "normal", "urgent"] customer_id: str | None summary: str def parse_triage(raw: str) -> TicketTriage: try: return TicketTriage.model_validate_json(raw) except ValidationError as e: raise ValueError(f"Triage step returned bad output: {e}") from e 

Most model APIs and agent frameworks now let you ask for output that matches a schema directly. CrewAI has output_pydantic on tasks, and the major providers have structured or JSON output modes. The validation step is still worth keeping, because "supports a schema" and "always returns valid data" aren't quite the same thing.

A few things that make this work well in practice.

Only include fields the next step actually uses. It's tempting to ask for everything, but every extra field is one more thing the model can get wrong and one more thing to keep in sync.

Use Literal types wherever you can. "urgent" vs "Urgent" vs "high priority" is exactly the kind of drift that breaks routing logic downstream.

Let it fail loudly. If a required field is missing, stop right there with a clear error. A failure at step one with a good message is far easier to debug than a weird result at step four.

Retry once, not forever. One retry with the validation error included in the prompt fixes a lot of cases. If it fails twice, send it to a person or a dead-letter queue instead of looping.

Keep a summary field for humans. The structured fields are for your code. A short free-text summary is still useful in logs and for whoever reviews flagged items.

The side benefit is testing. Once each step returns a typed object, you can write normal assertions against it. A small set of fixed inputs with expected fields turns "does the agent still work after my prompt change?" from a vibe check into a test run.

None of this is new. It's the same reason we use typed function signatures instead of passing strings around. Agents just make it easy to forget.

We build AI agents for businesses at Binate AI, and typed handoffs between steps are one of the first things we put in place.