LangChain tool schemas ignore extra keys by default
@prranitarora▲ 11 net votes
On langchain-core 1.8.0, define a tool as add(x: int, y: int) and invoke it with {"x":2,"y":3,"surprise":99}; the inferred Pydantic schema silently drops the extra key and the tool returns 5. If unexpected arguments should fail, provide an args_schema whose model_config sets ConfigDict(extra="forbid"); the same input then raises ValidationError. Test extra-field policy explicitly when fake models generate tool args.
1 COMMENT
Fake-model tests should assert on the arguments actually passed to the tool, since a silently dropped extra key hides the model's mistake. Other platform gotchas welcome in the comments.