You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the AutoCompleteRequest model in my codebase defines field descriptions using multi-line docstrings. This approach is problematic for integrations with LLMs, particularly when generating tool call schemas using .model_json_schema().
Example of the current implementation:
classAutoCompleteRequest(BaseModel):
input: Annotated[
str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
]
r"""States, cities, districts, addresses, zipcode. Example: New York """limit: Annotated[
Optional[int],
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
] =10r"""The number of items per response, for paging purpose. Example: 2 """
Since description is not explicitly provided in Field(), this results in loss of metadata when calling .model_json_schema(), making it difficult to generate proper tool call schemas in LangGraph’s Tool API.
Proposed Solution
Instead of using multi-line docstrings, the field descriptions should be provided via pydantic.Field(description=...). This allows .model_json_schema() to correctly generate a structured schema.
Updated version:
classAutoCompleteRequest(BaseModel):
input: Annotated[
str, Field(
description="States, cities, districts, addresses, zipcode. Example: New York",
metadata={"query": QueryParamMetadata(style="form", explode=True)}
)
]
limit: Annotated[
Optional[int],
Field(
default=10,
description="The number of items per response, for paging purposes. Example: 2",
metadata={"query": QueryParamMetadata(style="form", explode=True)}
)
]
This change ensures that .model_json_schema() generates a proper OpenAPI schema, improving compatibility with LangGraph's Tool API.
simplesagar
changed the title
Field descriptions from openapi spec should be in pydantic.Field and not in mutli-line strings
[DOCS-4834] Field descriptions from openapi spec should be in pydantic.Field and not in mutli-line strings
Mar 27, 2025
Issue Description
Currently, the
AutoCompleteRequest
model in my codebase defines field descriptions using multi-line docstrings. This approach is problematic for integrations with LLMs, particularly when generating tool call schemas using.model_json_schema()
.Example of the current implementation:
Since
description
is not explicitly provided inField()
, this results in loss of metadata when calling.model_json_schema()
, making it difficult to generate proper tool call schemas in LangGraph’s Tool API.Proposed Solution
Instead of using multi-line docstrings, the field descriptions should be provided via
pydantic.Field(description=...)
. This allows.model_json_schema()
to correctly generate a structured schema.Updated version:
This change ensures that
.model_json_schema()
generates a proper OpenAPI schema, improving compatibility with LangGraph's Tool API.DOCS-4834
The text was updated successfully, but these errors were encountered: