Home / Function/ test_tool_injected_arg_with_custom_schema() — langchain Function Reference

test_tool_injected_arg_with_custom_schema() — langchain Function Reference

Architecture documentation for the test_tool_injected_arg_with_custom_schema() function in test_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  5abda9cc_db37_b1d2_1d12_62906199fc40["test_tool_injected_arg_with_custom_schema()"]
  8e7836ae_e72c_f670_72a5_4ca6d46e3555["test_tools.py"]
  5abda9cc_db37_b1d2_1d12_62906199fc40 -->|defined in| 8e7836ae_e72c_f670_72a5_4ca6d46e3555
  style 5abda9cc_db37_b1d2_1d12_62906199fc40 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/test_tools.py lines 2481–2509

def test_tool_injected_arg_with_custom_schema() -> None:
    """Ensure InjectedToolArg works with custom args schema."""

    class InputSchema(BaseModel):
        query: str

    class CustomContext:
        """Custom context object to be injected."""

        def __init__(self, value: str) -> None:
            self.value = value

    captured: dict[str, Any] = {}

    @tool(args_schema=InputSchema)
    def search_tool(
        query: str, context: Annotated[CustomContext, InjectedToolArg]
    ) -> str:
        """Search with custom context."""
        captured["context"] = context
        return f"Results for {query} with context {context.value}"

    # Test that context is properly injected even though not in custom schema
    ctx = CustomContext("test_context")
    result = search_tool.invoke({"query": "hello", "context": ctx})

    assert result == "Results for hello with context test_context"
    assert captured["context"] is ctx
    assert captured["context"].value == "test_context"

Domain

Subdomains

Frequently Asked Questions

What does test_tool_injected_arg_with_custom_schema() do?
test_tool_injected_arg_with_custom_schema() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/test_tools.py.
Where is test_tool_injected_arg_with_custom_schema() defined?
test_tool_injected_arg_with_custom_schema() is defined in libs/core/tests/unit_tests/test_tools.py at line 2481.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free