This prompt is for AI operations engineers and platform developers who need to enforce runtime governance on tool calls made by an LLM assistant. The job-to-be-done is embedding a hard policy into the system prompt that limits the number, frequency, and cumulative cost of tool executions within a single user session, preventing runaway loops, quota exhaustion, and unexpected infrastructure bills. The ideal user is someone integrating an LLM into a production product where tool calls consume billable API credits, database resources, or third-party service quotas, and where silent overconsumption is a direct business risk.
Prompt
Tool Execution Budget and Rate Limit Prompt Template

When to Use This Prompt
Define the job, reader, and constraints for the Tool Execution Budget and Rate Limit Prompt Template.
Use this prompt when you have a defined set of tools with known cost weights, a per-session budget ceiling, and a requirement for the assistant to communicate its remaining budget to the user gracefully. It is appropriate for chat-based copilots, coding agents with sandboxed execution, and multi-step research assistants that call external APIs. Do not use this prompt when tool calls are free, unlimited, or managed entirely by external circuit breakers in the application layer. It is also insufficient as the sole control for hard real-time rate limiting; the prompt should be paired with deterministic application-level guards that enforce the budget even if the model ignores or misinterprets the instruction.
Before implementing, define your tool cost table, per-session budget, and the desired degradation behavior—whether the assistant should refuse further calls, offer a degraded path, or escalate to a human. The prompt template expects these as concrete variables. Start by copying the template, filling in your tool definitions and budget parameters, and then run eval checks for budget exhaustion, user communication clarity, and adherence under multi-turn pressure. If the workflow involves high-cost or irreversible tool calls, add a human approval gate before execution, not just a budget check.
Use Case Fit
Where the Tool Execution Budget and Rate Limit prompt template works, where it breaks, and what operational risks to manage before deployment.
Good Fit: Cost-Constrained Agent Loops
Use when: An agent can autonomously call tools in a loop and you need a hard stop to prevent runaway spending. Guardrail: The prompt enforces a per-session budget that the model can track and report before the execution layer is invoked.
Bad Fit: Hard Real-Time Rate Limiting
Avoid when: You need microsecond-level rate limiting or token-bucket enforcement. Risk: The prompt is a behavioral policy, not a network-level throttle. Guardrail: Implement actual rate limiting in the API gateway or tool proxy; use this prompt only for graceful user communication and pre-flight budget checks.
Required Input: Budget Declaration
What to watch: Without a concrete budget value injected into the prompt, the model has no boundary to enforce. Guardrail: Always inject a specific [MAX_TOOL_CALLS], [MAX_COST_CENTS], or [RATE_LIMIT_PER_MINUTE] variable from the application layer. Never rely on the model to infer limits from vague instructions.
Operational Risk: Budget Exhaustion Deadlock
What to watch: The model hits the budget mid-task and stops without a clear handoff, leaving the user with a partial result and no path forward. Guardrail: The prompt must include explicit instructions for a graceful degradation message that explains what was completed, what remains, and how the user can continue or increase the budget.
Operational Risk: Budget Gaming by the Model
What to watch: The model may batch unnecessary tool calls early or avoid useful calls to stay under an artificial limit, degrading output quality. Guardrail: Include a policy statement that prioritizes task completion quality over strict budget adherence, and instruct the model to request a budget increase if needed rather than silently producing bad results.
Operational Risk: Silent Budget Tracking Failures
What to watch: The model loses count of tool calls across long contexts or complex multi-step plans. Guardrail: Require the model to output a running budget counter in its reasoning or a structured field after each tool call. Validate this counter in the application layer and trigger a hard stop if the model's count diverges from the actual execution log.
Copy-Ready Prompt Template
A reusable system prompt that enforces per-session tool call budgets, rate limits, and cost thresholds with graceful degradation.
This prompt template is designed to be placed in the system instructions of a tool-augmented assistant. It defines a hard governance layer that sits between the model's reasoning and the tool execution layer. The prompt enforces three constraints: a maximum number of tool calls per session, a minimum delay between successive calls, and a cumulative cost ceiling. When a limit is reached, the assistant must stop calling tools and communicate the state clearly to the user. The template uses square-bracket placeholders so you can wire in your own thresholds, tool cost registry, and escalation policy without rewriting the behavioral logic.
markdownYou are an assistant with access to external tools. Your tool usage is governed by the following budget and rate limit policy. You must enforce this policy yourself before every tool call. Do not rely on the user or an external system to stop you. ## Budget and Rate Limits - **Per-Session Tool Call Budget:** You may make a maximum of [MAX_TOOL_CALLS_PER_SESSION] tool calls in this conversation. This count includes all tool calls, regardless of success or failure. - **Rate Limit:** You must wait at least [MIN_SECONDS_BETWEEN_CALLS] seconds between the end of one tool call and the start of the next. Do not batch or parallelize calls to circumvent this limit. - **Cost Threshold:** Each tool has an associated cost in [COST_UNIT]. The costs are defined in the tool cost registry below. You must track the cumulative cost of all tool calls made in this session. You may not exceed a total session cost of [MAX_SESSION_COST] [COST_UNIT]. ## Tool Cost Registry [TOOL_COST_REGISTRY] <!-- Example: - search_knowledge_base: 1 credit - execute_sql_query: 5 credits - send_email: 10 credits - generate_report: 15 credits --> ## Pre-Call Checklist Before every tool call, you must internally verify: 1. The next call will not exceed the remaining call budget. 2. The required wait time since your last tool call has elapsed. 3. The cost of the intended tool, when added to the current session total, will not exceed the maximum session cost. If any check fails, **do not call the tool**. Instead, inform the user which limit has been reached and what options are available. ## Budget Exhaustion Behavior When a limit is reached, you must: - State clearly which limit was hit (call budget, rate limit, or cost threshold). - Report the current session usage: calls made, total cost accrued. - Offer alternative paths that do not require additional tool calls, such as providing a partial answer, suggesting manual steps, or requesting an escalation if [ESCALATION_POLICY] permits. - Never suggest that the user "try again" to bypass the limit. ## User Communication - When informing the user of a limit, be concise and helpful. Do not apologize excessively. - If a user asks to override a limit, state that you are not authorized to do so and refer them to the escalation path defined in [ESCALATION_POLICY]. - Do not reveal the raw numerical thresholds unless the user asks directly about your capabilities. ## Tracking Maintain an internal counter for tool calls and cumulative cost. You may output a brief summary of remaining budget when asked, but do not include it in every response.
To adapt this template, replace the square-bracket placeholders with your production values. The [TOOL_COST_REGISTRY] should be a structured list mapping each tool name to its cost. If you use a dynamic cost model, replace the static registry with a reference to a tool that the assistant can call to look up costs—but be aware that the lookup itself consumes budget. The [ESCALATION_POLICY] placeholder should contain a short instruction, such as "ask the user to contact their admin" or "automatically open a human review ticket." Test the adapted prompt with sessions that intentionally exhaust each limit to confirm the assistant stops calling tools and communicates correctly. If your application layer also enforces these limits, treat the prompt as a first line of defense that provides a better user experience, not as the sole enforcement mechanism.
Prompt Variables
Inputs the prompt needs to enforce tool execution governance reliably. Each placeholder must be populated before the system prompt is assembled and sent to the model.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[TOOL_CALL_BUDGET] | Maximum number of tool calls allowed per session before the assistant must stop and summarize. | 20 | Must be a positive integer. Reject if null or non-numeric. Validate at session start. |
[RATE_LIMIT_WINDOW_SEC] | Time window in seconds for the rate limit counter. | 60 | Must be an integer >= 1. Reject if zero or negative. Used to calculate calls-per-window. |
[MAX_CALLS_PER_WINDOW] | Maximum tool calls permitted within [RATE_LIMIT_WINDOW_SEC]. | 5 | Must be an integer >= 1. Must not exceed [TOOL_CALL_BUDGET]. Validate relationship. |
[COST_THRESHOLD_USD] | Estimated cost ceiling per session. Assistant must warn and stop if cumulative tool cost exceeds this. | 0.50 | Must be a positive float. Reject if null. Cost tracking requires external calculator integration. |
[BUDGET_EXHAUSTION_MESSAGE] | User-facing message template when the tool call budget is exhausted. | I've reached my tool call limit for this session. Here is a summary of what I completed. | Must be a non-empty string. Validate for clarity and absence of technical jargon. Test for user comprehension. |
[RATE_LIMIT_HIT_MESSAGE] | User-facing message template when the rate limit is hit mid-window. | I need to pause tool use briefly to stay within limits. I'll continue in a moment. | Must be a non-empty string. Validate that it communicates a temporary state, not a permanent failure. |
[COST_THRESHOLD_WARNING] | User-facing message template when approaching the cost threshold. | This operation may exceed the session cost limit. Do you want me to proceed? | Must be a non-empty string. Validate that it requests explicit user confirmation before proceeding. |
Implementation Harness Notes
How to wire the budget enforcement prompt into an agent loop with counters, resets, and logging.
The Tool Execution Budget and Rate Limit prompt is not a standalone artifact; it is a policy layer that must be enforced by the application runtime. The prompt instructs the model to track its own tool calls and respect limits, but the application must act as the authoritative source of truth. Implement a server-side counter that increments before each tool call is dispatched and decrements the model's declared remaining budget. If the model attempts to exceed the budget, the application should reject the tool call and inject a system message informing the model that the budget is exhausted, rather than relying solely on the model's self-restraint.
Build the harness around three core components: a budget state object, a pre-flight check middleware, and a budget-exhaustion handler. The budget state object should track max_calls, calls_made, reset_condition (e.g., per-session, per-hour sliding window), and graceful_degradation_mode. The pre-flight middleware intercepts every tool call request from the model, checks calls_made < max_calls, and either forwards the call or triggers the exhaustion handler. The exhaustion handler should inject a structured system message like SYSTEM: Tool call budget exhausted. [calls_made] of [max_calls] used. You may only respond with a summary of what was accomplished and guidance for the user on how to proceed. This message must be prepended to the context window before the next inference call to prevent the model from hallucinating additional tool calls.
Logging is critical for debugging budget enforcement. For every tool call, log a structured record containing timestamp, session_id, tool_name, call_number, budget_remaining, model_declared_remaining, and action_taken (allowed, denied, exhaustion_injected). Discrepancies between budget_remaining and model_declared_remaining indicate the model has lost count and the application should correct it via a system message. For rate limits, implement a token-bucket or sliding-window algorithm at the application layer and expose the current state to the model through a [RATE_LIMIT_STATUS] placeholder in the prompt that gets populated at inference time with values like "3 calls remaining in this 60-second window; next reset at 14:32:15 UTC." Never trust the model to enforce time-based rate limits on its own.
When deploying this prompt in production, pair it with an eval harness that tests budget exhaustion behavior explicitly. Create test scenarios where the budget is 0 from the start, where the budget is exhausted mid-task, and where the budget is sufficient. Assert that the model never makes a tool call when calls_made >= max_calls, that the exhaustion message is clear and actionable, and that the model does not fabricate tool results. For high-stakes workflows, add a human approval gate that triggers when the budget is exhausted but the task is incomplete, offering the user the option to extend the budget with an explicit confirmation step rather than leaving the conversation in a broken state.
Expected Output Contract
Defines the required fields, types, and validation rules for the assistant's response when a tool execution budget or rate limit is encountered. Use this contract to build a parser that can reliably extract budget status and user-facing messages from the model output.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
budget_status | string enum: [active, warning, exhausted] | Must be exactly one of the allowed enum values. Parse check: reject any other string. | |
remaining_calls | integer >= 0 | Must be a non-negative integer. If budget_status is exhausted, this value must be 0. Schema check: type enforcement. | |
rate_limit_reset_seconds | integer >= 0 or null | Must be an integer >= 0 if a rate limit is active; otherwise null. If budget_status is active, this should be null. Null allowed. | |
cost_threshold_percent | integer 0-100 | Must be an integer between 0 and 100 representing the percentage of the cost budget consumed. Range check: reject values outside 0-100. | |
user_message | string, max 300 chars | A concise, non-technical message explaining the current budget or rate limit status to the end user. Must not expose internal thresholds or raw numbers. Length check: truncate if > 300 chars. | |
graceful_degradation_action | string enum: [proceed, queue, block, escalate] | Must be one of the allowed actions. If budget_status is exhausted, this must be block or escalate. If active, must be proceed. Logic check: cross-field consistency. | |
tool_call_blocked | boolean | Must be true if a specific tool call was prevented due to budget or rate limits; otherwise false. If true, user_message must explain the block. Consistency check. | |
escalation_required | boolean | Must be true if human approval or admin override is required to proceed; otherwise false. If true, graceful_degradation_action must be escalate. Cross-field validation. |
Common Failure Modes
What breaks first when tool execution budgets are exhausted and how to guard against it.
Silent Budget Exhaustion
What to watch: The assistant hits its per-session tool call limit and stops executing tools without informing the user, leading to incomplete tasks or fabricated results. Guardrail: Instruct the model to proactively announce remaining budget after each tool call and to explicitly state when the budget is exhausted, offering a summary of completed work and a clear path to continue in a new session.
Rate Limit Retry Storms
What to watch: The assistant encounters a 429 rate limit, retries immediately, and enters a loop that burns through the remaining budget on failed calls. Guardrail: Embed a strict retry policy in the system prompt that mandates exponential backoff, a maximum of 2 retries, and immediate escalation to the user with the specific wait time if the limit persists.
Degraded Output Fabrication
What to watch: When a tool is unavailable due to budget or rate limits, the model falls back to its internal knowledge and generates a plausible-sounding but ungrounded answer instead of admitting the tool is blocked. Guardrail: Add a hard rule that states: 'If a required tool cannot be called due to budget or rate limits, you must not substitute with internal knowledge. You must inform the user that the action is blocked and why.'
Partial Completion Without Checkpointing
What to watch: A multi-step workflow is interrupted mid-way by a budget cap, leaving the system in an inconsistent state with no record of what was completed. Guardrail: Require the assistant to output a structured checkpoint after every critical tool call, logging the action taken, its result, and the next required step, so a new session can resume from the last valid state.
Cost Threshold Blindness
What to watch: The assistant executes an expensive tool call that consumes the majority of the budget in a single step, leaving no capacity for the remaining workflow. Guardrail: Implement a pre-flight check instruction that forces the model to estimate the cost of a tool call against the remaining budget and ask for user confirmation before executing any call that would consume more than 50% of the remaining allocation.
User Communication Breakdown
What to watch: The assistant uses overly technical jargon like 'token budget exceeded' or '429 error' that confuses the end-user, leading to frustration and support tickets. Guardrail: Provide a mandatory user-facing message template in the prompt that translates all budget and rate limit failures into plain, actionable language, such as 'I've reached my limit for this task. Here's what I finished and how to pick it up.'
Evaluation Rubric
Use this rubric to test budget enforcement and user communication before shipping. Each criterion targets a specific failure mode in tool execution governance.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Budget Exhaustion Response | Assistant refuses further tool calls with a clear explanation of the limit reached and offers a non-tool alternative | Assistant silently stops calling tools, makes unauthorized tool calls, or returns a generic error without context | Run a session that exhausts [MAX_TOOL_CALLS_PER_SESSION] and verify the final refusal message matches [BUDGET_EXHAUSTION_LANGUAGE] |
Rate Limit Backoff Communication | Assistant informs the user of the rate limit, states the required wait time, and does not retry until the window resets | Assistant retries immediately, uses vague language like 'try again later', or fails to mention the specific cooldown period | Trigger [RATE_LIMIT_WINDOW] exhaustion and check that the response includes the wait duration from [RATE_LIMIT_COOLDOWN] |
Cost Threshold Warning | Assistant warns the user when estimated session cost reaches [COST_WARNING_THRESHOLD] and requests confirmation before continuing | Assistant exceeds the warning threshold without notification or continues without user acknowledgment | Simulate tool calls with known costs until the cumulative total crosses [COST_WARNING_THRESHOLD] and check for the confirmation prompt |
Cost Hard Limit Enforcement | Assistant stops all tool execution when cumulative cost reaches [COST_HARD_LIMIT] and explains the session is blocked | Assistant allows any tool call after the hard limit is reached or provides no explanation for the stoppage | Continue tool calls past the warning threshold until [COST_HARD_LIMIT] is hit and verify no further tool calls are attempted |
Graceful Degradation on Budget Exhaustion | Assistant offers to complete the task using only its internal knowledge, explicitly noting the limitations of doing so | Assistant claims it can no longer help at all or fabricates tool results to appear functional | After budget exhaustion, ask the assistant to complete a task that would normally require a tool and check for the internal-knowledge fallback with caveats |
User Communication Clarity | Every budget-related message includes: what limit was hit, what the user can do next, and when/if the limit resets | Messages are missing one or more of the three required components or use internal jargon the user cannot act on | Review all budget-related responses against the [USER_COMMUNICATION_TEMPLATE] schema for completeness |
Session Reset Handling | Assistant correctly resets all counters (calls, cost, rate limit window) when a new session is started and does not carry over stale state | Assistant refuses tool calls in a new session due to the previous session's exhausted budget | Exhaust the budget in session A, start session B with a fresh [SESSION_ID], and verify tool calls are allowed |
Concurrent Session Isolation | Budget counters for one session do not affect another concurrent session | Tool call refusal in session A due to budget exhaustion also blocks tool calls in session B | Run two sessions simultaneously, exhaust budget in session A, and confirm session B can still make tool calls up to its own limit |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a single budget counter. Use a simple JSON state object to track remaining_calls and session_budget. Inject the current count into the system prompt at each turn. Skip persistent storage—keep state in memory for the session.
code[SYSTEM] You have a tool call budget of [MAX_CALLS] per session. You have used [USED_CALLS] so far. Before calling any tool, check if [USED_CALLS] >= [MAX_CALLS]. If so, inform the user and stop.
Watch for
- Budget state drifting across turns if the application layer doesn't update the prompt
- Model ignoring the budget when it's close to the limit
- No graceful degradation message—model just stops mid-task

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us