Skip to content
Blog

System Instruction Optimization: Meta-Prompting for Deterministic Tool Calling

Turn tool selection from hopeful guessing into a decision table: structuring the system instruction, decision rules and negative examples, few-shot tool transcripts, meta-prompting as an iteration loop, and evals that keep it honest.

Published on • November 27, 2026

AI Assistant

Give an agent twelve tools and a vague instruction and you get twelve plausible-but-wrong calls per session. Tool selection feels like a model capability problem, but most erratic tool behaviour is a documentation problem: the system instruction never told the model how to choose.

This article treats the system instruction as executable specification — a decision table the model follows — and introduces meta-prompting: using an LLM to iterate on that specification, with evals closing the loop so the iteration doesn’t become vibes-based tuning.

Why tool calling goes nondeterministic

Before fixing it, know the failure classes:

  1. Ambiguous tool overlap. search_kb and search_tickets both “find things”. The instruction never says which applies to which intent.
  2. Missing preconditions. The model calls issue_refund without an order ID because nothing told it to confirm first.
  3. Wrong granularity. The model uses query_database with a hand-written SQL string when get_order_status was built for exactly that.
  4. Eager calling. The model calls a tool before it has enough of the user’s intent, then again, then again.
  5. Fabricated arguments. Missing required fields get plausible defaults — the classic source of silently wrong results.

All five are resolved by the same thing: explicit, checkable rules in the instruction.

Anatomy of an instruction that selects tools reliably

The shape that works has five sections, in this order:

1. ROLE         — one sentence: what this agent is for, and its boundaries.
2. DECISION TABLE — intent → tool, as an exhaustive ordered list.
3. PRECONDITIONS — what must be known/true before each tool may be called.
4. NEGATIVE RULES — what never to do, with the tempting case it prevents.
5. OUTPUT CONTRACT — when to answer without tools; how to report tool results.

A condensed example:

You are the billing assistant for Acme. You may ONLY use these tools.

DECIDE IN THIS ORDER:
1. User asks about an invoice's status  -> get_invoice(invoice_id). Requires invoice_id.
   If the invoice_id is missing -> ask for it. Do NOT guess or invent one.
2. User asks to change a payment method -> update_payment_method. Requires an authenticated session.
3. User disputes a charge -> dispute_charge. NEVER call without explicit user confirmation
   of the amount in the dispute.
4. General questions about how billing works -> answer from your own knowledge, no tools.

NEVER:
- Call more than one tool in a single step unless the rules above require two.
- Fabricate identifiers. If a required argument is unknown, ask the user.
- Retry a failed tool call with the same arguments; report the error instead.

ANSWER FORMAT: after tool results arrive, reply in two sentences max, then a bullet
list of the facts you retrieved, each with the field it came from.

Why this works: it converts an open-ended generation problem into a lookup. The model isn’t deciding “what would help here”, it’s matching intent against rows.

Key details

  • Order matters. List rules most-specific-first, so a general rule doesn’t shadow a specific one.
  • Enumerate the tools you will not always need. If you add a tool and don’t add its row, the model will use it opportunistically — every tool addition is an instruction change.
  • Negative rules must name the tempting case. “Don’t guess” is weak; “do not invent an invoice_id” is enforceable.
  • Say when not to call anything. Otherwise models over-call on questions they can answer directly.

Few-shot transcripts beat abstract rules

Where a rule is hard to state, show the sequence. A compact tool-use transcript in the instruction anchors argument shape, ordering, and refusal style:

EXAMPLE
User: "Where's my order from Tuesday?"
Assistant: [tool call get_orders(date='2026-11-24', status='any')]
           [tool response: {orders: [{id: 'A-991', status: 'shipped'}]}]
Assistant: "Your order A-991 from Tuesday is shipped and arrives tomorrow."

Two or three of these — including one negative example where the right move is to ask rather than call — typically cut wrong-argument calls more than any amount of prose.

Meta-prompting: iterating on the instruction with an LLM

Meta-prompting is prompting a model to improve your prompt. Done naively it drifts; done as a loop with measurements it becomes prompt engineering with evidence.

async def meta_prompt_iteration(instruction: str, failures: list[dict]) -> str:
    critique = await judge_model.analyze(
        f"""Below is a system instruction for an agent with these tools:
{tool_schema}

These are recent tool-calling failures (expected vs actual):
{failures}

Identify the smallest set of instruction changes that would prevent each failure.
Rules: add at most 5 lines, never remove an existing rule, keep the DECISION TABLE
format, and do not mention specific failing transcripts by ID.
Return ONLY the revised instruction.""",
        config={'temperature': 0.2},
    )
    return critique.text

The guardrails are what make it safe:

  • Change one thing per iteration (or at most a handful of lines), so attributing improvement stays possible.
  • Keep a frozen eval set. Every candidate instruction runs against the same cases; improvement must be measured on held-out failures, not the ones you just showed it.
  • Diff before you ship. An LLM rewriting an instruction will happily delete the negative rules you needed most.
  • Version instructions like code. instruction/v7.md with a changelog entry tying each edit to a failure bucket.

Verifying: the eval that makes it deterministic

“Deterministic tool calling” means “correct in the cases you defined”. Build a labelled set: (user turn + history) → expected tool, expected args — 50–200 cases is enough to catch regressions. Score exact tool match and argument-field match separately; they fail for different reasons.

score = {
    'tool_match':      predicted_tool == expected_tool,
    'required_args':    all(predicted.args.get(k) == v for k, v in expected.required.items()),
    'no_extra_calls':   len(predicted_calls) == 1,
}

Run it in CI against every instruction change and every tool addition. Tool selection is the cheapest part of an agent to regress-test, because the oracle is a label you already wrote.

Takeaways

  • Tool nondeterminism is mostly missing specification: write a decision table, preconditions, negative rules, and an output contract.
  • Every tool you add needs a row; unlisted tools get used opportunistically.
  • Few-shot tool transcripts — including one “ask instead of call” case — outperform abstract exhortations.
  • Meta-prompting works as a loop: frozen eval set, small diffs, human review of the rewrite.
  • Ship instruction changes behind an eval gate, exactly like code.

Further reading