Skip to content

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

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

Open
adityaprakash-work opened this issue Mar 15, 2025 · 0 comments
Labels

Comments

@adityaprakash-work
Copy link

adityaprakash-work commented Mar 15, 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:

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

@simplesagar 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants