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

StructuredTool.From_function Injects Spurious V__args Field Into JSON Schema When Function Parameter Is Named Args

When a function has a parameter named `args`, StructuredTool.from_function generates a JSON schema with a spurious `v__args` field (type array, empty items) instead of the actual `args` parameter. This breaks Gemini API tool schema validation and causes silent parameter loss.

highConfidence 95%Langchain-CoreAgentsEmbeddingsRetrieversAffected V0.3.0Affected V1.2.17

Origin Analysis

StructuredTool.from_function uses Pydantic's deprecated `ValidatedFunction` decorator to generate the args schema. That wrapper injects a sentinel field named `args` to guard against unexpected positional arguments, and if the wrapped function already has a parameter named `args`, it renames the sentinel to `v__args`. This sentinel is still included in the generated schema as a list[Any] with default null, rendered as {"type": "array", "items": {}}. Meanwhile, the legitimate `args` parameter is dropped due to the name collision.
Run the provided Python code: define a function `run_command(working_dir: str, args: list[str], timeout: int = 60)`, wrap it with `StructuredTool.from_function`, and inspect `st.args_schema.model_json_schema()['properties']`. Observe that the `args` parameter is replaced by `v__args`, and `v__args` has an empty `items` array.

Fixing Code Block

Edge Case Audit

This hotfix uses Pydantic v2's `validate_call` which may differ in validation strictness and error messages from the deprecated `ValidatedFunction`. It requires Pydantic v2 (>=2.0). If the code relies on the old behavior's handling of extra positional arguments, it may break. Concurrency/multithreading is not affected because the patch is applied once at import time. When upgrading langchain-core, this patch may need to be removed or adjusted if the upstream fix is merged. Rollback: remove the monkey patch and use the original `_get_schema_from_func` (restore function reference).

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