Files
hermes-agent/tests/tools/test_web_tools_empty_query.py
Teknium a529212a00 fix(web): an empty web_search query is refused before any backend runs
A model that called web_search with query='' sent it to the configured
backend (Perplexity: VALIDATION_ERROR) and then through the whole fallback
chain (Firecrawl: "Query cannot be empty"), producing provider errors the
model could not act on. web_search_tool now returns a plain tool error naming
the missing argument, without calling any provider.

Fixes #152227
2026-11-14 03:43:05 -08:00

21 lines
726 B
Python

"""An empty ``web_search`` query is refused before any backend is called."""
import json
import pytest
import tools.web_tools
from tools.registry import registry
assert tools.web_tools.web_search_tool # importing registers web_search
@pytest.mark.parametrize("args", [{"query": ""}, {"query": " "}])
def test_empty_query_is_refused_without_calling_a_provider(args, monkeypatch):
def _no_provider(*_a, **_k):
raise AssertionError("an empty query must not reach a search provider")
monkeypatch.setattr("tools.web_tools._memoized_search", _no_provider)
result = json.loads(registry.dispatch("web_search", args))
assert result["success"] is False
assert "non-empty 'query'" in result["error"]