Skip to content
mentoor

Prompt structure for a ten-tool system prompt

For engineers

Structure, thinking, decomposition, a prompt library, caching and sampling for a complex system prompt.

A ten-tool support agent holds together when its prompt is sectioned and ordered, briefed with goals, split into small jobs, kept in a versioned library, laid out for caching, and sampled at settings that suit each job.

The case

Tern Payments is a small payments company. Its support agent, Tern Ops, runs on a Claude model through an API, and the team also tests the same prompt on GPT and Gemini models. Ops has ten tools: search_orders, get_customer, get_shipment, search_kb, create_ticket, refund_create, refund_status, update_address, send_email and escalate_to_human.

The system prompt began as 400 words. After a year of fixes it is 2,600 words. Rules repeat. Two rules disagree about refund limits. A customer's pasted email sits in the middle of the instructions. Last week Ops quoted a refund limit that had been replaced, and the finance lead asked why the monthly API bill keeps rising. This scenario follows the rebuild, one skill at a time.

Why it matters

A long prompt fails quietly. Models skip rules, mix up instructions and data, and answer with the same confidence either way. With tools that move money and send email, a skipped rule is an incident. A prompt that nobody can read, test or version cannot be fixed with confidence.

How to do it

1. Separate instructions from data (structure). Give each part its own tag: <role>, <tool_rules>, <policy>, <ticket>, <question>. Put the long policy documents first and the actual question last. Treat the ticket text as untrusted: a customer can write anything in it, including "ignore your rules". Tags and escaping make this harder but never remove the risk, so the tools themselves also enforce limits.

2. Brief for the goal, not the method (thinking). Where the model reasons before answering, say what a good outcome is, the constraints, and when to stop and escalate. Do not script every thought. Choose a reasoning effort per route: more for disputed refunds, less for formatting an address. Read reasoning summaries to find a misread rule, but do not treat them as proof of how the answer was made.

3. Give each prompt one job (decompose). Classify the ticket, gather facts with tools, decide, then write the reply. Each step hands a small output to the next, and a check sits between steps. A deterministic check, such as "refund amount is not more than the order total", beats asking a model whether the output looks fine.

4. Keep prompts in a library (library). Each prompt has an owner, named placeholders, a change log that says what changed and why, and a few saved test tickets that are run again after every model update.

5. Lay the prompt out for caching (caching). Prompt caching reuses an identical beginning of a request at a lower price and delay. The order is tools, system prompt, policy documents, then per-request data. A timestamp near the top, a reordered tool list or a customer name in the prefix changes the beginning and the cache misses every time. Check the cached-token fields in the usage data of each route.

6. Set sampling per job (sampling). Extraction and refund decisions want low randomness and a pinned model version. A reply draft can use more. Even at temperature zero, answers can differ between runs, so repeatable behaviour comes from tests, not from one setting. Where a decision is uncertain, sampling several times and sending disagreements to a person turns randomness into a signal.

Before and after

Before: one 2,600-word prompt. The ticket sits in the middle, the question comes first, a timestamp opens the prompt, and a single call classifies, decides and writes. After: five tagged sections, documents then question, the timestamp moved to the end, three small calls with a check between them, and a library entry with a change log.

What goes wrong

  • Tags are added but the customer's text is never escaped, so a ticket can close the tag and write its own instructions.
  • The team trusts a reasoning summary as evidence that a rule was followed, and stops testing.
  • A tidy-up that sorts the tools alphabetically silently resets the cache on every request.
  • Temperature is set to zero and the regression tests are deleted, then a model update changes behaviour unseen.

Steps

  1. Section the prompt and keep the ticket as data

    Skill: prompt-structure

    Split the 2,600 words into tagged sections. Policy documents come first, the ticket next, the question last. Say once that ticket text is data, never instructions, and enforce refund limits in the refund_create tool as well, since tags alone do not stop injection.

    Skeleton of the rebuilt system prompt

    prompts/ops-system.xml

    <role>You are Tern Ops, a support agent for Tern Payments.</role><tool_rules>  refund_create: only after search_orders confirms the order.  send_email: only drafts; a person approves.</tool_rules><policy>...refund and shipping policy documents...</policy><ticket>{{ticket_text_escaped}}</ticket><question>Decide the next action for this ticket.</question>
  2. Brief for the outcome and set effort per route

    Skill: prompt-thinking

    State the goal, the constraints and the stopping rule instead of a numbered method. Choose effort per route: low for address formatting, high for disputed refunds. Ask for a short plan to review before any money tool is called.

    Reasoning effort by route
    RouteError costLatency targetEffort
    Address format checkLow2 sLow
    Refund under limitMedium8 sMedium
    Disputed refundHigh30 sHigh
  3. Split the work into small jobs with checks

    Skill: prompt-decompose

    Classify, gather facts, decide, then draft. Each step returns a small structured result. Between decide and draft, a plain code check compares the refund to the order total and to the limit, and stops the chain when it fails.

    Ops ticket chain

    Goal: Resolve a ticket without dropping a rule

    1. Classify the ticket (check: label is in the allowed list)
    2. Gather facts with search_orders and get_shipment (check: order id matches the ticket)
    3. Decide the action (check: refund <= order total and <= limit)
    4. Draft the reply (check: includes the policy source)
    5. Hand to a person for approval
  4. Put the prompt in a versioned library

    Skill: prompt-library

    Store each prompt with an owner, named placeholders and a change log. Keep five or six saved tickets, including a past failure and an injection attempt, and run them again after every model or prompt change.

    Library entry

    Name

    ops-refund-decision, owner: Mara (support engineering)

    v7, 2026-11-20

    Replaced the 30-day refund rule with the 14-day rule. Why: policy page changed on 2026-11-12. Result: 6 of 6 saved tickets pass; the disputed-refund ticket now escalates.

  5. Order the request for cache hits

    Skill: context-caching

    Keep the beginning of every request identical: tool definitions, system prompt, policy documents. Put the time, the ticket and the question after them. Read the cached-token fields in the usage data to confirm that hits happen.

    Request layout, top to bottom
    1. tools (fixed order, ten definitions)2. system prompt (fixed text)3. policy documents (change only on policy edits)4. current time5. ticket text6. question
  6. Choose sampling settings per job

    Skill: llm-sampling

    Use low randomness and a pinned model version for extraction and decisions, more for drafts. Do not rely on temperature zero for repeatability: keep the saved tickets as regression tests. For an uncertain decision, sample a few times and send disagreements to a person.

    Sampling settings
    JobTemperatureNotes
    Extract order id0Structured output, pinned model
    Decide refund0Plus saved-ticket tests
    Draft reply0.7A person approves

Skills this scenario uses

Where to study