feat: support Standard Schema tool validators - #793
Open
LukasParke wants to merge 5 commits into
Open
Conversation
LukasParke
marked this pull request as ready for review
August 11, 2026 23:02
- convertToolsToAPIFormat: check inputJsonSchema before the Zod fast path so the explicit escape hatch always wins - StandardSchemaError: stringify symbol path segments so JSON.stringify and formatToolExecutionError no longer crash or emit null paths - tool<TShared>() overload: require inputJsonSchema for plain Standard Schema v1 validators via a non-inferred union config (explicit type arguments disable inference for remaining type parameters) Add regression tests for all three.
InferToolOutput matched a required outputSchema property, but regular and manual tools declare it optional, so their result types collapsed to unknown (Devin Review finding on PR #793). Match the property as optional and filter non-schema values instead. Add tests/unit/tool-types.test-d.ts: vitest typecheck only covers *.test-d.ts files, so the expectTypeOf assertions in .test.ts files were never typechecked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
inputSchema,outputSchema, andeventSchemaStandardSchemaV1.InferInputandInferOutput, while preserving the existing Zod inference and synchronous validation overloadsschema['~standard'].validate(...), including asynchronous validators and normalized Standard Schema issuesinputJsonSchema~-prefixed JSON Schema metadataWhy
The tool system was hard-wired to Zod even though Valibot, ArkType, Effect Schema, and other validators expose the shared Standard Schema v1 interface. Supporting that interface removes validator lock-in while keeping existing Zod tools unchanged.
Design decisions
JSON Schema
Provider JSON Schema follows a three-tier chain:
z4.toJSONSchema(..., { target: 'draft-7' }), including Zod versions that predate the companion trait.~standard.jsonSchema.inputconvert with thedraft-07target. Converter failures fall through to the explicit fallback.inputJsonSchema: callers can provide the wire schema directly. This is required when neither automatic path applies and overrides the Standard JSON Schema trait when supplied.The Standard JSON Schema trait is supported by Zod 4.2+, ArkType 2.1.28+, Zod Mini, VineJS, and Sury. Valibot adds it with
toStandardJsonSchema()from@valibot/to-json-schema.Only input schemas need provider JSON Schema because output and event schemas are local runtime validators. Every generated or explicit schema is sanitized before being sent downstream.
Compatibility
tool()definitions need no changes.validateToolInput/validateToolOutputcalls with Zod remain synchronous and continue throwingZodError.Test coverage
toStandardJsonSchema()inputJsonSchemaoverride precedence~metadata sanitizationVerification
pnpm buildpnpm typecheckpnpm lintpnpm test— 201 tests passed, type errors: 0pnpm test:e2eattempted during the initial implementation; 3 model-list tests passed and 22 API-backed tests failed because the configured OpenRouter credential returned401 User not found