AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Tool Schemas And Invocation Diverge For Valid Pydantic And Python Signatures

In langchain-core 1.5.6, creating tools from Pydantic models or Python functions can produce schemas that do not match the actual invocation contract. Field aliases and validation aliases are lost, serialization-only exclusions remove validated inputs, positional-only and variadic parameters are mishandled, and falsey exceptions are swallowed.

highConfidence 92%Langchain-CoreChat Modelslangchain-coreAffected V1.5.6

Origin Analysis

The subset model creation for tool_call_schema uses a naive field extraction that drops Pydantic FieldInfo metadata. During invocation, the code calls model_dump() which applies serialization rules (e.g., Field(exclude=True)), stripping valid inputs. Parameter binding treats all validated fields as keyword arguments, breaking positional-only and *args signatures. Exception handling tests the exception instance's truthiness (`if exc:`) instead of checking for None, causing falsey exceptions to be ignored.
Run the provided Python snippet on langchain-core 1.5.6. It defines tools with aliased Pydantic fields, excluded fields, positional-only arguments, variadic *args, and a falsey exception. The observed output shows: alias schema lacking 'external' key, TypeError for excluded field, internal 'v__positional_only' leaking into schema, TypeError for positional-only as keyword, TypeError for variadic values, and None instead of raising FalseyError.

Fixing Code Block

Edge Case Audit

This fix may introduce compatibility issues with older Pydantic versions (below v2) or custom model configurations. Ensure that all installed packages are compatible with the updated internal API. In concurrent or multi-threaded environments, the new argument binding logic must be thoroughly tested with async and variadic functions to avoid race conditions. When rolling back, revert all related changes simultaneously; partial rollback could leave tools with mismatched schemas, causing model-facing errors.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state