Skip to main content

How to add standard tests to a tool

When creating either a custom tool or a new tool to publish in a LangChain integration, it is important to add standard tests to ensure the tool works as expected. This guide will show you how to add standard tests to a tool.

Setup​

First, let's install 2 dependencies:

  • langchain-core will define the interfaces we want to import to define our custom tool.
  • langchain-standard-tests (installed as a git dependency) will provide the standard tests we want to use.
note

The langchain-standard-tests package is not released to pypi, so we need to install it from the git repository.

This will always pull in the latest version of the package.

%pip install -U langchain-core "git+https://github.com/langchain-ai/langchain.git#subdirectory=libs/standard-tests"

Let's start with the custom tool defined in the first part of how to create tools.

from langchain_core.tools import tool

@tool
def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
API Reference:tool

Add and configure standard tests​

There are 2 namespaces in the langchain-standard-tests package: unit tests (langchain_standard_tests.unit_tests) and integration tests (langchain_standard_tests.integration_tests).

Unit tests are designed to be used to test the tool in isolation and without access to external services.

Integration tests are designed to be used to test the tool with access to external services (in particular, the external service that the tool is designed to interact with).


Was this page helpful?