[Bug]: clarify tool schema `maxLength: 8000` breaks every request on llama.cpp servers ("Failed to initialize samplers: failed to parse grammar")
Bug Description
Summary
Since commit a4c31d592b9 ("fix(tools): reject all-blank and over-limit clarify choices…"), the clarify tool schema includes "maxLength": 8000 on choices.items. llama.cpp's JSON-schema-to-grammar converter rejects any repetition count ≥ 2000, so every chat completion request to a llama.cpp server fails with HTTP 400 — even a plain "hello", because the tool list is always sent.
Error
HTTP 400: Failed to initialize samplers: failed to parse grammar
layer: provider, code: format_error, retryable: falseEnvironment
- Hermes: v0.21.5+5673.g00373b5 (main @ 00373b53761), Windows 11, desktop app
- Provider: custom OpenAI-compatible endpoint → llama.cpp server (
owned_by: llamacpp), GGUF model - Last working build: 5f75ec197b16 (worked), 2fa2f42d412 and later fail
Reproduction
- Point Hermes at a llama.cpp server (custom provider,
api_mode: chat_completions). - Send any message → 400 above.
Isolated by sending each of the 24 tools individually from the request dump (HERMES_DUMP_REQUESTS=1) to the server:
clarify → choices.items.maxLength |
Result |
|---|---|
| 8000 (current) | ❌ failed to parse grammar |
| 2000 | ❌ failed to parse grammar |
| 1999 | ✅ OK |
| removed | ✅ OK |
All other tools pass individually; the full 24-tool request succeeds once maxLength is removed from clarify.
Cause
tools/clarify_tool.py:
"items": {"type": "string", "maxLength": MAX_CHOICE_CHARS}, # MAX_CHOICE_CHARS = 8000llama.cpp expands maxLength into a bounded repetition and caps it at < 2000.
Suggested fix
Drop maxLength from the schema. The limit is already enforced at runtime in clarify_tool.py (the len(choice.strip()) > MAX_CHOICE_CHARS check), so behavior is unchanged:
- "items": {"type": "string", "maxLength": MAX_CHOICE_CHARS},
+ "items": {"type": "string"},I've applied this locally, and requests to llama.cpp work again.
More generally, it may be worth stripping or clamping maxLength/maxItems ≥ 2000 from tool schemas for llama.cpp/local providers (similar to agent/gemini_schema.py), so a future schema change can't take down all local-model users.
Steps to Reproduce
Steps to Reproduce
A. Through Hermes
- Start a llama.cpp server (
llama-serverwith--jinja, any GGUF model). - Add it to
config.yamlas a custom provider:model: default: <model-name> provider: my-llamacpp base_url: http://<host>:<port>/v1 api_mode: chat_completions providers: my-llamacpp: base_url: http://<host>:<port>/v1 model: <model-name> - Send any message, for example:
hermes -z "hello" - Expected: the model replies.
Actual: the request fails at once with:This happens on every turn, including the first message of a new session, because the
HTTP 400: Failed to initialize samplers: failed to parse grammarclarifytool is always in the tool list.
B. Minimal reproduction without Hermes (curl only)
This sends one tool whose schema copies the choices part of clarify:
curl -s http://<host>:<port>/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "<model-name>",
"max_tokens": 1,
"messages": [{"role": "user", "content": "hello"}],
"tools": [{"type": "function", "function": {
"name": "clarify",
"parameters": {"type": "object", "properties": {
"choices": {"type": "array", "items": {"type": "string", "maxLength": 8000}}
}}
}}]
}'Result:
{"error":{"code":400,"message":"Failed to initialize samplers: failed to parse grammar","type":"invalid_request_error"}}With "maxLength": 1999, or with maxLength removed, the same request succeeds. Any value ≥ 2000 fails.
Expected Behavior
Expected Behavior
- Hermes should keep working with llama.cpp servers (and other OpenAI-compatible local servers that turn tool schemas into grammars) as it did before a4c31d592b9. A normal message like "hello" should get a normal reply.
- Built-in tool schemas should not use JSON Schema constraints that common local inference backends reject. Here,
maxLengthonclarify→choices.itemsshould be removed, or kept below 2000. The 8000-character limit on choices can still be enforced at runtime, asclarify_tool.pyalready does. - If a tool schema does cause a provider-side grammar error, the error should point to the cause, for example by naming the tool or schema, instead of only suggesting "pick another model". A malformed tool definition should not leave the user with no working model.
Actual Behavior
Actual Behavior
Every request to the llama.cpp server is rejected before any text is generated:
HTTP 400: Failed to initialize samplers: failed to parse grammarIt happens on every turn. A brand-new session that only sends "hello" fails the same way, because the
clarifytool is always in the tool list. Hermes is unusable with this provider.Hermes does not retry. The error is classified as
format_error/retryable: false, and the turn ends after one attempt:WARNING agent.conversation_loop: API call failed (attempt 1/3, not retryable) error_type=BadRequestError ... summary=HTTP 400: Failed to initialize samplers: failed to parse grammar ERROR agent.conversation_loop: Non-retryable client error: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}The hint points the wrong way. The user is told:
custom rejected this request as malformed, so the model didn't answer. Start a clean session with /new or switch models with /model; if it keeps happening, run
hermes doctor.Neither
/newnor switching to another model on the same llama.cpp server helps, because the bad schema comes from Hermes and not from the session or the model.The server itself is healthy. The same server answers normally when
clarifyis left out or itsmaxLengthis below 2000. The regression appeared right after updating from 5f75ec197b16 to 2fa2f42d412, with no change on the server side.
Affected Component
Other
Messaging Platform (if gateway-related)
No response
Debug Report
## Debug Report
<details>
<summary><code>hermes debug share --local</code> (dump section + relevant log excerpt, IP/paths redacted)</summary>
--- hermes dump ---
version: 0.21.5+5673.g00373b5 [00373b53] (2026-10-01)
os: Windows 11 AMD64
python: 3.14.7
openai_sdk: 2.24.0
profile: <profile>
model: <model-name> (GGUF on llama.cpp server)
provider: custom (named custom provider, api_mode: chat_completions)
terminal: local
features:
toolsets: hermes-cli
mcp_servers: 0
memory_provider: built-in
platforms: none
skills: 85
config_overrides:
agent.max_turns: 500
display.streaming: True
--- end dump ---
--- agent.log (excerpt) ---
INFO hermes_cli.main: Checkout changed since last launch (git:refs/heads/main:5f75ec197b16 -> git:refs/heads/main:2fa2f42d412a)
INFO tools.tool_search: tool_search activated (tier 1): 22 core/visible tools kept, 16 deferred (~7463 tokens), listing full (budget ~4000 tokens)
INFO agent.turn_context: conversation turn: ... model=<model-name> provider=custom platform=desktop history=0 msg='hello'
INFO run_agent: OpenAI client created (chat_completion_stream_request, shared=False) ... provider=custom base_url=http://<llama-host>:<port>/v1
ERROR agent.chat_completion_helpers: Streaming failed before delivery: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
Traceback (most recent call last):
File "agent/chat_completion_helpers.py", line 3868, in _call
File "agent/chat_completion_helpers.py", line 3845, in _call_wire
File "agent/chat_completion_helpers.py", line 3194, in _call_chat_completions
File "agent/relay_llm.py", line 329, in _start_unmanaged
File "agent/chat_completion_helpers.py", line 3085, in _open_chat_stream
return request_client.chat.completions.create(**stream_kwargs)
File ".../openai/_base_client.py", line 1070, in request
openai.BadRequestError: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
WARNING agent.conversation_loop: API call failed (attempt 1/3, not retryable) error_type=BadRequestError ... summary=HTTP 400: Failed to initialize samplers: failed to parse grammar
ERROR agent.conversation_loop: Non-retryable client error: Error code: 400 - {'error': {'code': 400, 'message': 'Failed to initialize samplers: failed to parse grammar', 'type': 'invalid_request_error'}}
INFO tui_gateway.server: tui turn finished: ... status=error error_retained=True duration=1.0s failure_reason=format_error cause='HTTP 400: Failed to initialize samplers: failed to parse grammar'
--- llama.cpp server (/v1/models) ---
owned_by: llamacpp, format: gguf, n_ctx: 131072, system_fingerprint: b0-unknown
</details>
Full request payload is available via `HERMES_DUMP_REQUESTS=1`; the only tool that fails on its own is `clarify` (see table above).Operating System
Windows11
Python Version
No response
Hermes Version
No response
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
No response
Proposed Fix (optional)
No response
Are you willing to submit a PR for this?
- I'd like to fix this myself and submit a PR
Source: NousResearch/hermes-agent