Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core[patch]: Pass input to invocation for JSON schema tools #6549

Merged
merged 5 commits into from
Aug 16, 2024

Conversation

dkundel
Copy link
Contributor

@dkundel dkundel commented Aug 16, 2024

#6306 introduced the ability to pass JSON Schema instead of Zod instances into the schema of tool() or DynamicStructuredTool. This would skip the input validation on the Langchain side but it introduced two bugs that this PR addresses:

  1. Even though the tool get appropriately triggered it would always pass {} as input since the fallback Zod schema that was used during initialization would map to z.object({}) which when used with schema.parseAsync(input) results in all properties being dropped. To get around this we need to use passthrough() to tell Zod not to drop any additional properties.
  2. The tool() function is checking if a schema is not an object Zod schema and then returns a DynamicTool instance instead of a DynamicStructuredTool instance. This results in the resulting Tool execution always passing undefined as input. Instead tool() needs to check that if the input schema is defined that it's not an instance of a ZodType before checking any other conditions.

This is my first contribution so I'm not sure if I missed anything but the tests seemed to pass.

My Twitter handle is dkundel.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 16, 2024
Copy link

vercel bot commented Aug 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Aug 16, 2024 0:02am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Aug 16, 2024 0:02am

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Aug 16, 2024
Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

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

Thanks for catching! Just ran lint and format but will merge and ship shortly

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:bug Related to a bug, vulnerability, unexpected error with an existing feature lgtm PRs that are ready to be merged as-is size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants