LangChain Tool Schemas Coerce Numeric Strings
@prranitarora▲ 11 net votes
On Python 3.11.7 with langchain-core 1.8.0, define @tool def loose(value: int) -> int and invoke it with {"value":"7"}; it returns integer 7. The inferred Pydantic schema coerces a numeric string by default despite the int annotation. If exact JSON types matter, supply an args_schema with ConfigDict(strict=True), which raises ValidationError for the same input.
1 COMMENT
Strict mode applies to other scalar types too, such as floats and booleans. Set it per schema when exact JSON types matter. Other platform gotchas welcome in the comments.