Support Pydantic json schema manipulation for tool schemas #31336
bengladwell
announced in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked
Feature request
Add a GenerateJsonSchema field to StructuredTool to allow control over tool schema generation.
Motivation
We have had a lot of difficulty working with OpenAI's Responses API because of Responses API's stricter rules regarding JSON schemas. We have encountered this common problem, which required us modify how we specify optional tool parameters.
We also had problems with tool parameters that are a discriminated union Pydantic type. After much back and forth with OpenAI support, it was determined that we need to remove default values from the discriminated field so that those fields are included in the JSON spec required array.
Rather than make our Pydantic models non-standard, it would be nice to just control the tool schema output. Of course, it is possible to simply generate the JSON schema and pass it directly to
SturcturedTool.from_function
as theargs_schema
argument. However, this bypasses the processing of tool args performed by Langchain, such as the removal of injected variables. We would like to have both: Langchain tool arg processing and control over how the schema is generated.Proposal (If applicable)
Add a field like:
to
langchain_core.tools.structured.StructuredTool
.Then, in
StructuredTool.args
, generate the json schema like:Beta Was this translation helpful? Give feedback.
All reactions