Fix: undefined def when using structured outputs in agent with zod pi…
Merged
TK
9mo ago+33+33+01234567890123456789-13-13-01234567890123456789
why
There is currently a bug isolated specifically to people using zod pinned to v3 with structured output in agent resulting in a zod error "undefined def"
what changed
We now ensure any output schema passed in is correctly normalized to v3 or v4 depending on what version is being used through our zodcompat factory
test plan
tested the failing scenario to make sure it is addressed
Summary by cubic
Fixes the “undefined def” error when agents use structured outputs with Zod pinned to v3 by building the “done” tool schema with the same Zod version as the user’s schema.
- Bug Fixes
- Use getZFactory to create schemas with the user’s Zod version (v3 or v4).
- Build the base done schema via the factory and safely extend with outputSchema.
- Generate output instructions using StagehandZodSchema types to avoid v3/v4 mixing.
- Add changeset to publish a patch release.