langchain · difficulty ◆◆
BaseTool Pydantic v1 Compatibility Fix
Define structured tools that work on both Pydantic v1 and v2.
Your tools should not care which Pydantic generation is installed. 1.4.7 makes that true.
$ python3 -c "import pydantic; print(pydantic.__version__)"What it does
This patch restores full compatibility between LangChain’s BaseTool / Tool classes and Pydantic v1. Prior to this fix, creating a BaseTool subclass using Pydantic v1-style field declarations (Field(default=None) without an explicit annotation, or validator decorators) would raise a ValidationError or silently produce broken tool schemas at runtime. The fix patches the internal create_schema logic in langchain-core/tools/runnable.py to handle both Pydantic v1 and v2 field representations.
Why it matters
A large proportion of production deployments are still on Pydantic v1 because upgrading to v2 requires code changes or depends on other libraries. Those deployments hit cryptic validation errors when defining custom tools with structured inputs. After the fix, you can define tools with Field regardless of the installed Pydantic version.
Example
$ Inspect a tool’s auto-generated schema=== Tool Schema ===
{
"$defs": {
"summarize_documentInput": {
"properties": {
"text": {"description": "The document text to summarize", "type": "string"},
"max_length": {"default": 200, "description": "Max summary length in words", "type": "integer"}
},
"required": ["text"],
"type": "object"
}
}
}
=== Tool Result ===
[Summary (20 words)]: LangChain is a framework for building applications...On Pydantic v1 the schema is now complete and correctly typed after upgrading to core 1.4.7.
Common flags
- Field(default=200)
- Pydantic v1-style default field declarations
- args_schema
- Explicit Pydantic model for tool input validation
History
Origin
Fixed in langchain-core==1.4.7 (2026-06-12), PR #33698, covered in the June 14 tutorial.
Compatibility layer
create_schema in tools/runnable now detects Pydantic v1 vs v2 field representations and handles both, regardless of environment.
Fun facts
Pros & cons
pros
- + Works on Pydantic v1 and v2
- + Correct args schemas everywhere
- + No forced v2 migration
cons
- − Only affects tools/runnable paths
- − Requires core 1.4.7
Takeaways
- 1Upgrade to langchain-core >=1.4.7 for Pydantic v1 tool support.
- 2Use get_input_schema().model_json_schema() to verify tool schemas are complete.
- 3Custom tools with Field work identically on v1 and v2 after the fix.