published fresh until

GBNF: how does a small local model call tools without broken JSON?

Summary Eris describes session GBNF grammars and narrowed per-turn subset grammars for local models. llama.cpp supports JSON Schema-to-GBNF conversion for a subset of JSON Schema; its guide recommends inspecting generated grammars and using llama-gbnf-validator.

Not for choosing a local model or a harness, or testing code in general; see local-coding-model-24-32gb-machine, local-model-16gb-gpu-which-agent-harness

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first (our recommendation): Constrain tool arguments with a schema-derived grammar, validate the call, and offer a relevant subset of tools. Our recommendation: include an uncertainty fallback when narrowing the tools offered.

The problem

Example scenario (our example): you run a small local model behind llama.cpp and your agent has dozens of tools. In this example, malformed tool-call JSON breaks the agent loop.

What the source says

The Eris README describes a local-first Rust agent with grammar-enforced tool calls on llama.cpp:

1. Compile a GBNF grammar per session to constrain output at the token level. 2. Use a narrowed per-turn subset grammar.

The repository carries an Apache-2.0 license.

What llama.cpp supports

The llama.cpp grammars README documents --grammar and --grammar-file for CLI tools, a grammar request field for server completions, and JSON Schema conversion through json_schema or /chat/completions's response_format.

For ordinary schema-constrained output, the schema is not injected into the prompt: describe the expected structure too. Native tool calling is an exception; its schemas are injected into the prompt.

The converter supports a subset of JSON Schema. Unsupported features can be silently skipped; inspect the generated grammar and use llama-gbnf-validator. The README still lists mixed properties with anyOf/oneOf, prefixItems and nested $refs as limitations; numeric bounds support integers rather than general numbers.

How to describe it to your agent

Our suggested instruction for your agent: Our local model's tool calls are malformed. Use a JSON Schema per tool and grammar-constrained generation. Validate arguments and tool permissions before execution. Route to relevant tools, widen the offer when uncertain, and derive both the prompt and grammar from that same list. Keep bounded recovery for invalid calls.

Mistakes to check

  • Eris's README says its intelligence ceiling is the GGUF you run.
  • The llama.cpp guide warns that unsupported schema features are silently skipped.
  • Our recommendation: check whether the narrowed tool set includes the intended tool.

Limits

Its README labels the project alpha. Our recommendation: assess tool choice separately from JSON validity.

Sources

Started from a post by @paulqq, packaged by the editor. Original post

Subjects

More in local models

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# GBNF: how does a small local model call tools without broken JSON?
Summary: Eris describes session GBNF grammars and narrowed per-turn subset grammars for local models. llama.cpp supports JSON Schema-to-GBNF conversion for a subset of JSON Schema; its guide recommends inspecting generated grammars and using `llama-gbnf-validator`.
Copy for agent
get the whatworks thread local-model-tool-calls-gbnf-grammar-narrow-tools and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread local-model-tool-calls-gbnf-grammar-narrow-tools
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks