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

genai: Fix required field is ignored when dealing with nested pydantic models #751

Merged
merged 3 commits into from
Feb 25, 2025

Conversation

ghengao
Copy link
Contributor

@ghengao ghengao commented Feb 25, 2025

PR Description

Fix missing required field in the tool schema when dealing with nested pydantic models. Following model

class MyModel(BaseModel):
    name: str
    age: int

class Models(BaseModel):
    models: list[MyModel]

Is not populating required field for nested MyModel

"function_declarations": [
            {
                "description": "",
                "name": "Models",
                         ...
                        "models": {
                            "description": "",
                            "enum": [],
                            "format_": "",
                            "items": {
                                "description": "MyModel",
                                "enum": [],
                            ...
                                    },
                                },
                                "required": [],   # <- Should be "required": ["name", "age"],
                                "type_": 6,
                            },
                            ...
                        }
                    },
                    "required": ["models"],
                    "type_": 6,
                },
            }
        ]
    }

Relevant issues

Fixes #690,

Type

🐛 Bug Fix

Changes(optional)

Testing(optional)

Note(optional)

@lkuligin lkuligin merged commit 3f143d6 into langchain-ai:main Feb 25, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants