test_tool_inherited_injected_arg() — langchain Function Reference
Architecture documentation for the test_tool_inherited_injected_arg() function in test_tools.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6637392e_2d6d_1e6c_3fe7_b510079fdfd1["test_tool_inherited_injected_arg()"] 8e7836ae_e72c_f670_72a5_4ca6d46e3555["test_tools.py"] 6637392e_2d6d_1e6c_3fe7_b510079fdfd1 -->|defined in| 8e7836ae_e72c_f670_72a5_4ca6d46e3555 beffa773_a4d3_0857_9757_4deff441ad96["_get_tool_call_json_schema()"] 6637392e_2d6d_1e6c_3fe7_b510079fdfd1 -->|calls| beffa773_a4d3_0857_9757_4deff441ad96 style 6637392e_2d6d_1e6c_3fe7_b510079fdfd1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/test_tools.py lines 1827–1888
def test_tool_inherited_injected_arg() -> None:
class BarSchema(BaseModel):
"""bar."""
y: Annotated[str, "foobar comment", InjectedToolArg()] = Field(
..., description="123"
)
class FooSchema(BarSchema):
"""foo."""
x: int = Field(..., description="abc")
class InheritedInjectedArgTool(BaseTool):
name: str = "foo"
description: str = "foo."
args_schema: type[BaseModel] = FooSchema
@override
def _run(self, x: int, y: str) -> Any:
return y
tool_ = InheritedInjectedArgTool()
assert tool_.get_input_schema().model_json_schema() == {
"title": "FooSchema", # Matches the title from the provided schema
"description": "foo.",
"type": "object",
"properties": {
"x": {"description": "abc", "title": "X", "type": "integer"},
"y": {"description": "123", "title": "Y", "type": "string"},
},
"required": ["y", "x"],
}
# Should not include `y` since it's annotated as an injected tool arg
assert _get_tool_call_json_schema(tool_) == {
"title": "foo",
"description": "foo.",
"type": "object",
"properties": {"x": {"description": "abc", "title": "X", "type": "integer"}},
"required": ["x"],
}
assert tool_.invoke({"x": 5, "y": "bar"}) == "bar"
assert tool_.invoke(
{
"name": "foo",
"args": {"x": 5, "y": "bar"},
"id": "123",
"type": "tool_call",
}
) == ToolMessage("bar", tool_call_id="123", name="foo")
with pytest.raises(ValidationError):
tool_.invoke({"x": 5})
assert convert_to_openai_function(tool_) == {
"name": "foo",
"description": "foo.",
"parameters": {
"type": "object",
"properties": {"x": {"type": "integer", "description": "abc"}},
"required": ["x"],
},
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_tool_inherited_injected_arg() do?
test_tool_inherited_injected_arg() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/test_tools.py.
Where is test_tool_inherited_injected_arg() defined?
test_tool_inherited_injected_arg() is defined in libs/core/tests/unit_tests/test_tools.py at line 1827.
What does test_tool_inherited_injected_arg() call?
test_tool_inherited_injected_arg() calls 1 function(s): _get_tool_call_json_schema.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free