Skip to content

fix(xai-responses): strip enum values containing '/' from tool schemas#28122

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-b83fc531
May 18, 2026
Merged

fix(xai-responses): strip enum values containing '/' from tool schemas#28122
teknium1 merged 2 commits into
mainfrom
hermes/hermes-b83fc531

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #28021 by @Slimydog21. Contributor's branch was severely stale (would have reverted ~5000 LOC across azure/kanban/i18n). Fix re-applied surgically on current main with their sanitizer + 9 tests preserved.

Summary

xAI's grammar compiler rejects enum values containing / (HuggingFace IDs from MCP-derived tools) with the same opaque HTTP 400 'Invalid arguments passed to the model' it raises for pattern/format. Adds strip_slash_enum() that drops the entire enum keyword (all-or-nothing — partial would still 400) but keeps the field description so the model still gets the prompting hint.

Changes

  • tools/schema_sanitizer.py: new strip_slash_enum() mirroring strip_pattern_and_format() structure
  • agent/chat_completion_helpers.py: wire into main-agent xAI Responses sanitization step
  • agent/auxiliary_client.py: same wire into aux-client xAI Responses path (parity with 2fae8fb for pattern/format)
  • tests/tools/test_schema_sanitizer.py: 9 new tests
  • scripts/release.py: AUTHOR_MAP noreply entry

Validation

scripts/run_tests.sh tests/tools/test_schema_sanitizer.py → 40/40 passing.

Closes #28021 (salvage merge — contributor authorship preserved via noreply email).

Slimydog21 and others added 2 commits May 18, 2026 10:36
xAI's /v1/responses and /v1/chat/completions endpoints reject tool schemas
whose enum values contain a forward slash with a generic HTTP 400 'Invalid
arguments passed to the model.' before any token is emitted — the schema
compiler trips on the '/' character regardless of where it appears.

Most commonly hit by MCP-derived tools whose enum lists HuggingFace model
IDs ('Qwen/Qwen3.5-0.8B', 'openai/gpt-oss-20b') or owner/name environment
identifiers.

Mirrors the existing strip_pattern_and_format sanitizer (PR for #27197).
The new strip_slash_enum walks tool parameters and drops the entire enum
keyword when any value contains '/' — keeping it partial would still 400
since xAI's failure is all-or-nothing on the enum. The field description
still reaches the model so the prompting hint is preserved.

Wired in at both code paths for parity:
  - agent/chat_completion_helpers.py (main agent xAI Responses path)
  - agent/auxiliary_client.py (aux client xAI Responses path, matching
    the same parity guarantee 2fae8fb established for pattern/format)

Salvaged from #28021 by @Slimydog21 — contributor's branch was severely
stale (would have reverted ~5000 LOC across azure/kanban/i18n); fix
re-applied surgically on current main with their sanitizer + 9 tests
preserved verbatim. Author noreply email used (original was a Mac
hostname leak).
@teknium1 teknium1 merged commit 47bc8e0 into main May 18, 2026
10 of 11 checks passed
@teknium1 teknium1 deleted the hermes/hermes-b83fc531 branch May 18, 2026 17:37
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-b83fc531 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8802 on HEAD, 8801 on base (🆕 +1)

🆕 New issues (1):

Rule Count
invalid-argument-type 1
First entries
tests/tools/test_schema_sanitizer.py:618: [invalid-argument-type] invalid-argument-type: Argument to function `strip_slash_enum` is incorrect: Expected `list[dict[Unknown, Unknown]]`, found `None`

✅ Fixed issues: none

Unchanged: 4622 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have provider/xai xAI (Grok) comp/agent Core agent loop, run_agent.py, prompt builder tool/mcp MCP client and OAuth labels May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have provider/xai xAI (Grok) tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants