Skip to content

[DOCS-4834] Field descriptions from openapi spec should be in pydantic.Field and not in mutli-line strings #1335

Open
@adityaprakash-work

Description

@adityaprakash-work

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:

class AutoCompleteRequest(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)),
    ] = 10
    r"""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:

class AutoCompleteRequest(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.

DOCS-4834

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions