Overview
Standard integration test suite for validating BaseTool implementations, verifying ToolCall handling and output schema compliance.
Description
ToolsIntegrationTests is a test suite class in the langchain-tests (standard-tests) package that extends ToolsTests (the unit test base). It provides integration-level tests for any BaseTool subclass, covering: synchronous invocation with ToolCall input validating ToolMessage output, asynchronous invocation with ToolCall input, synchronous invocation with plain kwargs (no ToolCall), and asynchronous invocation with plain kwargs. The tests verify that tools correctly produce ToolMessage content (string or list of strings/dicts) and handle content_and_artifact response formats.
Usage
Import this test suite when developing a custom tool integration and you need to verify that it correctly handles ToolCall inputs, produces valid ToolMessage outputs, and works both synchronously and asynchronously.
Code Reference
Source Location
- Repository: Langchain_ai_Langchain
- File:
libs/standard-tests/langchain_tests/integration_tests/tools.py
- Lines: 1-94
Signature
class ToolsIntegrationTests(ToolsTests):
"""Base class for tools integration tests."""
def test_invoke_matches_output_schema(self, tool: BaseTool) -> None:
...
async def test_async_invoke_matches_output_schema(self, tool: BaseTool) -> None:
...
def test_invoke_no_tool_call(self, tool: BaseTool) -> None:
...
async def test_async_invoke_no_tool_call(self, tool: BaseTool) -> None:
...
Import
from langchain_tests.integration_tests.tools import ToolsIntegrationTests
I/O Contract
Inherited Properties (from ToolsTests)
| Name |
Type |
Required |
Description
|
| tool_constructor |
BaseTool |
Yes |
The BaseTool subclass or instance to test.
|
| tool_constructor_params |
dict[str, Any] |
No |
Constructor parameters for the tool. Defaults to empty dict.
|
| tool_invoke_params_example |
dict[str, Any] |
No |
Example args for invocation (not a ToolCall dict). Defaults to empty dict.
|
Test Methods
| Test |
Description
|
| test_invoke_matches_output_schema |
Invokes the tool with a ToolCall and verifies the returned ToolMessage has valid content (str or list of str/dict). Also checks that content_and_artifact tools return a non-None artifact.
|
| test_async_invoke_matches_output_schema |
Async version of test_invoke_matches_output_schema.
|
| test_invoke_no_tool_call |
Invokes the tool with plain kwargs (not a ToolCall) and verifies no error is raised.
|
| test_async_invoke_no_tool_call |
Async version of test_invoke_no_tool_call.
|
Outputs (test_invoke_matches_output_schema)
| Name |
Type |
Description
|
| ToolMessage.content |
list[str | dict] |
The content of the tool message must be a string or a list of strings/dicts.
|
| ToolMessage.artifact |
Any |
For content_and_artifact tools, must not be None.
|
Usage Examples
Basic Usage
from typing import Any
from langchain_core.tools import BaseTool
from langchain_tests.integration_tests.tools import ToolsIntegrationTests
class TestMyTool(ToolsIntegrationTests):
@property
def tool_constructor(self) -> type[BaseTool]:
return MyCustomTool
@property
def tool_constructor_params(self) -> dict[str, Any]:
return {"api_key": "test-key"}
@property
def tool_invoke_params_example(self) -> dict[str, Any]:
return {"query": "example search query"}
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.