test_tools.py — langchain Source File
Architecture documentation for test_tools.py, a python file in the langchain codebase. 30 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR e870136a_4fe1_4e00_2c09_1d4f86a16ff2["test_tools.py"] 614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 614e7b9f_ed51_0780_749c_ff40b74963fc 7025b240_fdc3_cf68_b72f_f41dac94566b["json"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 7025b240_fdc3_cf68_b72f_f41dac94566b d76a28c2_c3ab_00a8_5208_77807a49449d["sys"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> d76a28c2_c3ab_00a8_5208_77807a49449d 243100a0_4629_4394_a66b_1f67b00ce784["textwrap"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 243100a0_4629_4394_a66b_1f67b00ce784 242d0b7d_a8ef_b66d_169b_c791b32a9cc9["threading"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 242d0b7d_a8ef_b66d_169b_c791b32a9cc9 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf["dataclasses"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf af34f08b_0ede_2b87_0db6_983d74ed0249["datetime"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> af34f08b_0ede_2b87_0db6_983d74ed0249 b188e880_71c6_b93e_127d_c22666293d37["enum"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> b188e880_71c6_b93e_127d_c22666293d37 c990f2d7_9509_7cea_ca95_51ad57dbe5c6["functools"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> c990f2d7_9509_7cea_ca95_51ad57dbe5c6 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 120e2591_3e15_b895_72b6_cb26195e40a6 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7 63ae09a2_4a67_3eaf_7888_b0fd11776a0e["pydantic.v1"] e870136a_4fe1_4e00_2c09_1d4f86a16ff2 --> 63ae09a2_4a67_3eaf_7888_b0fd11776a0e style e870136a_4fe1_4e00_2c09_1d4f86a16ff2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test the base tool implementation."""
import inspect
import json
import sys
import textwrap
import threading
from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime
from enum import Enum
from functools import partial
from typing import (
Annotated,
Any,
Generic,
Literal,
TypeVar,
cast,
get_type_hints,
)
import pytest
from pydantic import BaseModel, ConfigDict, Field, ValidationError
from pydantic.v1 import BaseModel as BaseModelV1
from pydantic.v1 import ValidationError as ValidationErrorV1
from typing_extensions import TypedDict, override
from langchain_core import tools
from langchain_core.callbacks import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from langchain_core.callbacks.manager import (
CallbackManagerForRetrieverRun,
)
from langchain_core.documents import Document
from langchain_core.messages import ToolCall, ToolMessage
from langchain_core.messages.tool import ToolOutputMixin
from langchain_core.retrievers import BaseRetriever
from langchain_core.runnables import (
RunnableConfig,
RunnableLambda,
ensure_config,
)
from langchain_core.tools import (
BaseTool,
StructuredTool,
Tool,
ToolException,
tool,
)
from langchain_core.tools.base import (
TOOL_MESSAGE_BLOCK_TYPES,
ArgsSchema,
InjectedToolArg,
InjectedToolCallId,
SchemaAnnotationError,
_DirectlyInjectedToolArg,
_is_message_content_block,
// ... (3574 more lines)
Domain
Subdomains
Functions
- HAS_LANGGRAPH()
- TEST_MODELS()
- _get_parametrized_tools()
- _get_tool_call_json_schema()
- _mock_structured_tool_with_artifact()
- _tool_func_annotated_injected()
- _tool_func_directly_injected()
- afoo()
- asimple_foo()
- assert_bar()
- foo()
- generate_backwards_compatible_v1()
- generate_models()
- injected_tool()
- injected_tool_with_schema()
- langgraph()
- simple_foo()
- test__get_all_basemodel_annotations_v2()
- test__is_message_content_block()
- test__is_message_content_type()
- test_args_kwargs_filtered()
- test_args_schema_as_pydantic()
- test_args_schema_explicitly_typed()
- test_async_exception_handling_bool()
- test_async_exception_handling_callable()
- test_async_exception_handling_non_tool_exception()
- test_async_exception_handling_str()
- test_async_tool_pass_config()
- test_async_tool_pass_context()
- test_async_validation_error_handling_bool()
- test_async_validation_error_handling_callable()
- test_async_validation_error_handling_non_validation_error()
- test_async_validation_error_handling_str()
- test_base_tool_inheritance_base_schema()
- test_convert_from_runnable_dict()
- test_convert_from_runnable_other()
- test_create_async_tool()
- test_create_retriever_tool()
- test_create_retriever_tool_get_type_hints()
- test_create_tool_keyword_args()
- test_create_tool_positional_args()
- test_decorated_function_schema_equivalent()
- test_decorator_with_specified_schema()
- test_decorator_with_specified_schema_pydantic_v1()
- test_docstring_parsing()
- test_empty_args_decorator()
- test_empty_string_tool_call_id()
- test_exception_handling_bool()
- test_exception_handling_callable()
- test_exception_handling_non_tool_exception()
- test_exception_handling_str()
- test_filter_injected_args_async()
- test_filter_injected_args_from_callbacks()
- test_filter_injected_args_not_in_schema()
- test_filter_multiple_injected_args()
- test_filter_run_manager_from_callbacks()
- test_filter_tool_runtime_directly_injected_arg()
- test_fn_injected_arg_with_schema()
- test_forward_ref_annotated_base_tool_accepted()
- test_get_all_basemodel_annotations_aliases()
- test_imports()
- test_injected_arg_with_complex_type()
- test_misannotated_base_tool_raises_error()
- test_missing_docstring()
- test_named_tool_decorator()
- test_named_tool_decorator_return_direct()
- test_nested_pydantic_fields()
- test_no_filtering_for_string_input()
- test_optional_subset_model_rewrite()
- test_simple_tool_args_schema_dict()
- test_structured_args()
- test_structured_args_decorator_no_infer_schema()
- test_structured_single_str_decorator_no_infer_schema()
- test_structured_tool_args_schema_dict()
- test_structured_tool_direct_init()
- test_structured_tool_from_function()
- test_structured_tool_from_function_docstring()
- test_structured_tool_from_function_docstring_complex_args()
- test_structured_tool_from_function_with_run_manager()
- test_structured_tool_from_parameterless_function()
- test_structured_tool_lambda_multi_args_schema()
- test_structured_tool_types_parsed()
- test_structured_tool_types_parsed_pydantic_mixed()
- test_structured_tool_types_parsed_pydantic_v1()
- test_structured_tool_with_different_pydantic_versions()
- test_subclass_annotated_base_tool_accepted()
- test_title_property_preserved()
- test_tool_ainvoke_does_not_mutate_inputs()
- test_tool_allows_extra_runtime_args_with_custom_schema()
- test_tool_annotated_descriptions()
- test_tool_annotations_preserved()
- test_tool_arg_descriptions()
- test_tool_args_schema_default_values()
- test_tool_args_schema_default_values_async()
- test_tool_args_schema_falsy_defaults()
- test_tool_args_schema_none_default()
- test_tool_args_schema_pydantic_v2_with_metadata()
- test_tool_args_schema_with_annotated_type()
- test_tool_call_id_empty_string_passed_to_callback()
- test_tool_call_id_none_when_invoked_without_tool_call()
- test_tool_call_id_passed_to_on_tool_start_callback()
- test_tool_call_id_passed_via_run_method()
- test_tool_call_input_tool_message_output()
- test_tool_call_input_tool_message_with_artifact()
- test_tool_content_block_output()
- test_tool_decorator_description()
- test_tool_description()
- test_tool_field_description_preserved()
- test_tool_from_function_with_run_manager()
- test_tool_inherited_injected_arg()
- test_tool_injected_arg()
- test_tool_injected_arg_with_custom_schema()
- test_tool_injected_arg_with_schema()
- test_tool_injected_arg_without_schema()
- test_tool_injected_tool_call_id()
- test_tool_injected_tool_call_id_override_llm_generated()
- test_tool_injected_tool_call_id_with_custom_schema()
- test_tool_invalid_docstrings()
- test_tool_invoke_does_not_mutate_inputs()
- test_tool_invoke_optional_args()
- test_tool_lambda_args_schema()
- test_tool_mutate_input()
- test_tool_partial_function_args_schema()
- test_tool_pass_config()
- test_tool_pass_config_non_pickleable()
- test_tool_pass_context()
- test_tool_return_output_mixin()
- test_tool_uninjected_tool_call_id()
- test_tool_with_kwargs()
- test_unnamed_decorator()
- test_unnamed_tool_decorator_return_direct()
- test_validation_error_handling_bool()
- test_validation_error_handling_callable()
- test_validation_error_handling_non_validation_error()
- test_validation_error_handling_str()
Classes
- AFooBase
- Address
- AnotherBaseModel
- Args
- ArgsSchema
- Bar
- BarSchema
- CalculatorInput
- CallbackHandlerWithInputCapture
- CallbackHandlerWithToolCallIdCapture
- ConfigArgs
- CustomContext
- EmptyModel
- FilterArgs
- Foo
- FooBase
- FooBaseNonPickleable
- FooProper
- FooSchema
- FooV1Namespace
- GSchema
- InheritedInjectedArgTool
- InjectedTool
- InjectedToolWithSchema
- InputSchema
- Mixin
- ModelA
- ModelB
- ModelC
- ModelD
- MyModel
- MyRetriever
- MyRuntime
- MyTool
- Person
- SearchArgs
- SomeBaseModel
- SomeEnum
- SomeTool
- _CustomRuntime
- _FakeExceptionTool
- _ForwardRefAnnotatedTool
- _MisAnnotatedTool
- _MockSchema
- _MockSchemaV1
- _MockSimpleTool
- _MockStructuredTool
- _MockStructuredToolWithRawOutput
- _RaiseNonValidationErrorTool
- _SingleArgToolWithKwargs
- _ToolArgsSchemaNoRuntime
- _VarArgToolWithKwargs
- fooSchema
Dependencies
- collections.abc
- dataclasses
- datetime
- enum
- functools
- inspect
- json
- langchain_core
- langchain_core.callbacks
- langchain_core.callbacks.manager
- langchain_core.documents
- langchain_core.messages
- langchain_core.messages.tool
- langchain_core.retrievers
- langchain_core.runnables
- langchain_core.tools
- langchain_core.tools.base
- langchain_core.utils.function_calling
- langchain_core.utils.pydantic
- langgraph.prebuilt
- pydantic
- pydantic.v1
- pytest
- sys
- tests.unit_tests.fake.callbacks
- tests.unit_tests.pydantic_utils
- textwrap
- threading
- typing
- typing_extensions
Source
Frequently Asked Questions
What does test_tools.py do?
test_tools.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_tools.py?
test_tools.py defines 135 function(s): HAS_LANGGRAPH, TEST_MODELS, _get_parametrized_tools, _get_tool_call_json_schema, _mock_structured_tool_with_artifact, _tool_func_annotated_injected, _tool_func_directly_injected, afoo, asimple_foo, assert_bar, and 125 more.
What does test_tools.py depend on?
test_tools.py imports 30 module(s): collections.abc, dataclasses, datetime, enum, functools, inspect, json, langchain_core, and 22 more.
Where is test_tools.py in the architecture?
test_tools.py is located at libs/core/tests/unit_tests/test_tools.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free