Skip to content

fix(zod): infer parsed tool callback arguments#1992

Open
HAYDEN-OAI wants to merge 2 commits into
mainfrom
dev/hayden/issue-1244-zod-tool-callback-types
Open

fix(zod): infer parsed tool callback arguments#1992
HAYDEN-OAI wants to merge 2 commits into
mainfrom
dev/hayden/issue-1244-zod-tool-callback-types

Conversation

@HAYDEN-OAI

Copy link
Copy Markdown
Contributor
  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Fixes #1244.

zodFunction() and zodResponsesFunction() already infer the parsed Zod output for the callback supplied in their options, but their returned auto-parseable tool types recorded the raw Zod schema type as arguments. Because AutoParseableTool and AutoParseableResponseTool use that field for their helper properties, callers saw $callback, $parseRaw, and __arguments typed as the schema object instead of the parsed tool arguments.

This updates both Zod helper return types to use InferZodType<Parameters> for arguments. The change is type-only and does not alter parsing or callback behavior at runtime.

The type regression checks now verify the inferred parsed argument type for $callback, $parseRaw, and __arguments on both chat completion and Responses API tools.

Additional context & links

@HAYDEN-OAI
HAYDEN-OAI marked this pull request as ready for review July 13, 2026 20:19
@HAYDEN-OAI
HAYDEN-OAI requested a review from a team as a code owner July 13, 2026 20:19
@openai-sdks

openai-sdks Bot commented Jul 13, 2026

Copy link
Copy Markdown

OkTest Summary

237/237 SDK tests passed in 11.553s for Node SDK PR #1992.

Test results — 42 files
Test Result Time
tests/chat-completions-complex-body.test.ts ✅ Passed 233ms
tests/chat-completions-create.test.ts ✅ Passed 248ms
tests/chat-completions-stream.test.ts ✅ Passed 139ms
tests/files-content-binary.test.ts ✅ Passed 160ms
tests/files-create-multipart.test.ts ✅ Passed 182ms
tests/files-list-pagination.test.ts ✅ Passed 184ms
tests/initialize-config.test.ts ✅ Passed 175ms
tests/instance-isolation.test.ts ✅ Passed 111ms
tests/models-list.test.ts ✅ Passed 147ms
tests/responses-background-lifecycle.test.ts ✅ Passed 217ms
tests/responses-body-method-errors.test.ts ✅ Passed 434ms
tests/responses-cancel-timeout.test.ts ✅ Passed 367ms
tests/responses-cancel.test.ts ✅ Passed 313ms
tests/responses-compact-retries.test.ts ✅ Passed 270ms
tests/responses-compact.test.ts ✅ Passed 257ms
tests/responses-create-advanced-stream.test.ts ✅ Passed 187ms
tests/responses-create-advanced.test.ts ✅ Passed 264ms
tests/responses-create-disconnect.test.ts ✅ Passed 1.082s
tests/responses-create-errors.test.ts ✅ Passed 284ms
tests/responses-create-malformed-api-responses.test.ts ✅ Passed 201ms
tests/responses-create-retries.test.ts ✅ Passed 271ms
tests/responses-create-stream-failures.test.ts ✅ Passed 156ms
tests/responses-create-stream-timeout.test.ts ✅ Passed 2.164s
tests/responses-create-stream-wire.test.ts ✅ Passed 2.606s
tests/responses-create-stream.test.ts ✅ Passed 135ms
tests/responses-create-terminal-states.test.ts ✅ Passed 343ms
tests/responses-create-timeout.test.ts ✅ Passed 338ms
tests/responses-create.test.ts ✅ Passed 237ms
tests/responses-delete.test.ts ✅ Passed 201ms
tests/responses-input-items-errors.test.ts ✅ Passed 186ms
tests/responses-input-items-list.test.ts ✅ Passed 212ms
tests/responses-input-items-options.test.ts ✅ Passed 217ms
tests/responses-input-tokens-count-timeout.test.ts ✅ Passed 351ms
tests/responses-input-tokens-count.test.ts ✅ Passed 268ms
tests/responses-malformed-inputs.test.ts ✅ Passed 2.344s
tests/responses-not-found-errors.test.ts ✅ Passed 333ms
tests/responses-parse.test.ts ✅ Passed 292ms
tests/responses-retrieve-retries.test.ts ✅ Passed 218ms
tests/responses-retrieve.test.ts ✅ Passed 285ms
tests/responses-stored-method-errors.test.ts ✅ Passed 613ms
tests/retry-behavior.test.ts ✅ Passed 3.279s
tests/sdk-error-shape.test.ts ✅ Passed 393ms

View OkTest run #29773261057

SDK merge (ba4f0805b389) · head (48903fde0a2c) · base (39a15b412fc1) · OkTest (fd7a761c81c1)

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the type flow for both Zod tool helpers and the new regression coverage. InferZodType<Parameters> matches the value returned by parseZodObject() and now propagates the parsed output type consistently through $callback, $parseRaw, and __arguments for both Chat Completions and Responses. The compareType assertions are exact, so they would fail if these properties regressed back to the schema object type.

I also validated the PR commit locally with the focused Zod suite (26 tests), pnpm build, and the full pnpm lint pipeline; all passed. No blocking issues found.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the current head (48903fd) after its merge with main. The corrected arguments: InferZodType<Parameters> generic now matches the value produced by parseZodObject() and consistently fixes $callback, $parseRaw, and __arguments for both Chat Completions and Responses tools. The exact type assertions cover all six affected surfaces, and the emitted CJS/ESM declarations retain the corrected inferred output type. No runtime behavior changes.

Local validation passed: focused Zod suite (26/26) and the full pnpm lint pipeline (Prettier, ESLint, CJS/ESM+Deno builds, tsc, Are The Types Wrong, publint, JSR dry-run). Current CI is green across Node 20/22/24/26.2, ecosystem tests, Agents SDK regressions, breaking-change detection, examples, and CodeQL. No blocking issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect type for callback function

2 participants