docs

Testing Tools

How to test tools built with the ninetrix SDK — unit tests, schema inspection, and registry utilities.

Because @Tool returns the original function unchanged, tools are just Python functions — test them directly with no special setup.

Unit testing the function

Python
from tools.db_tools import query_customers

def test_returns_list():
    result = query_customers("SELECT id FROM customers LIMIT 1")
    assert isinstance(result, list)

def test_default_limit():
    # default limit is 100 — verify your impl respects it
    result = query_customers("SELECT id FROM customers")
    assert len(result) <= 100

Inspecting the generated schema

Import your tool file to trigger registration, then use the registry to verify the schema the LLM will see:

Python
from ninetrix import _registry
import tools.db_tools  # side effect: registers tools

def test_schema_has_required_sql():
    td = _registry.get("query_customers")
    assert td is not None
    assert "sql" in td.parameters["required"]

def test_limit_is_optional():
    td = _registry.get("query_customers")
    assert "limit" not in td.parameters.get("required", [])

Resetting the registry between tests

If you need a clean slate between tests (e.g. to test discovery isolation), call _registry.clear():

Python
import pytest
from ninetrix import _registry

@pytest.fixture(autouse=True)
def clean_registry():
    yield
    _registry.clear()
No mocking needed
Because tools are plain functions, you can test them with real databases in CI or swap in fixtures — whatever fits your testing strategy.
On this page