Back to cookbook

ChatGPT Prompt for Reliable Function and Tool Calling

❀️1
20 views Published

Make this prompt yours

Share

This is a function and tool calling prompt for developers wiring ChatGPT, Claude, or Gemini into an app that has real tools available β€” a search API, a database lookup, a calculator, a calendar. It solves the most common failure mode in tool-using assistants: the model either calls a tool when it didn't need to, skips a tool call when it should have used one, or fabricates a plausible-looking function argument instead of asking for a missing value.

The template works by giving the model an explicit decision rule before it sees the tool list: check whether the question can be answered from context alone, check whether a required argument is actually present in the conversation, and only then call a tool. It also forces the model to state why it's calling a tool, which makes bad calls easy to catch in logs and easy to debug when a pipeline misbehaves.

This is not model-specific β€” the same decision structure works whether you're wiring up OpenAI's function calling, Anthropic's tool use, or Gemini's function declarations, since the reasoning happens in the prompt, not the API schema.

Prompt template

Make this prompt yours

prompt-template
217 tokens
You are an assistant with access to the following tools: [TOOL_1_NAME]: [ONE-LINE DESCRIPTION OF WHAT IT DOES AND WHEN TO USE IT] [TOOL_2_NAME]: [ONE-LINE DESCRIPTION OF WHAT IT DOES AND WHEN TO USE IT] Before responding to the user, work through these steps: 1. Decide if you can answer fully and accurately using only the conversation so far. If yes, answer directly and do not call any tool. 2. If a tool is genuinely needed, identify which single tool is the best fit. Do not call a tool "just in case." 3. List the required arguments for that tool. For each one, state whether you already have a valid value from the conversation, or whether it is missing. 4. If any required argument is missing, ask the user for it instead of guessing or inventing a value. 5. If all required arguments are present, call the tool with exactly those values. Context: [DESCRIBE THE USER'S REQUEST OR TASK HERE] Respond now, following the steps above.

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
225 tokens
You are an assistant with access to the following tools: get_weather: Returns current weather for a given city. Use only when the user asks about current or upcoming weather conditions. send_email: Sends an email on the user's behalf. Use only when the user explicitly asks you to send or draft-and-send an email. Before responding to the user, work through these steps: 1. Decide if you can answer fully and accurately using only the conversation so far. If yes, answer directly and do not call any tool. 2. If a tool is genuinely needed, identify which single tool is the best fit. Do not call a tool "just in case." 3. List the required arguments for that tool. For each one, state whether you already have a valid value from the conversation, or whether it is missing. 4. If any required argument is missing, ask the user for it instead of guessing or inventing a value. 5. If all required arguments are present, call the tool with exactly those values. Context: The user says: "What's it like outside right now?" Respond now, following the steps above.

When to use it

  • You're building an agent or chatbot that has one or more tools/functions available and it's calling them inconsistently
  • The model is calling a tool even when the answer was already in the conversation or system prompt
  • The model is guessing at required arguments instead of asking the user for missing information
  • You need a debuggable trail of why each tool call happened, not just which tool was called

Best practices

  • List each tool with a one-line description of exactly when to use it, not just what it does
  • Require the model to name which required arguments it has and which are missing before calling anything
  • Tell the model explicitly that it's allowed to answer directly with no tool call when no tool is needed
  • Test the prompt against edge cases where a tool looks relevant but isn't actually required

Common mistakes

  • Listing tools without saying when NOT to use them, so the model defaults to calling one every turn
  • Letting the model invent a plausible value for a missing required argument instead of asking for it
  • Not asking the model to explain its reasoning, making bad tool calls invisible until they break something downstream
  • Assuming the same prompt structure automatically transfers across providers without checking each one's tool-calling format

FAQs

Does this prompt work the same way for OpenAI, Claude, and Gemini function calling?

The reasoning structure (decide, pick one tool, check arguments, ask if missing) is model-agnostic and works for all three. What differs is the technical schema each provider expects for the tool definitions themselves β€” this prompt handles the reasoning, not the API-level schema.

Why does the prompt make the model explain its reasoning before calling a tool?

Without an explicit reasoning step, bad tool calls are hard to catch until something breaks downstream. Forcing the model to state which tool it picked and why makes incorrect or unnecessary calls visible in logs before they cause a problem.

How do I stop the model from calling a tool on every single turn?

Most over-calling happens because the tool descriptions only say what a tool does, not when to use it. Add an explicit "use only when..." condition to every tool description, and tell the model directly that answering with no tool call is a valid outcome.

What should the model do if a required argument is missing?

It should ask the user for the missing value rather than guessing. The prompt template makes this an explicit step so the model isn't left to decide on its own whether guessing is acceptable.

Can this prompt handle a case where more than one tool could apply?

Yes β€” step 2 asks the model to pick the single best-fit tool rather than calling multiple tools speculatively. If your use case genuinely needs multiple sequential tool calls, extend step 5 to loop back to step 1 after each call.

Found this prompt useful? Share it.

Share

More in Prompt Fundamentals & Techniques

Prompt Fundamentals & Techniques

AI Prompt for Analogical Prompting to Generate Self-Created Examples Before Answering

Analogical prompting is a technique where, instead of you writing few shot examples by hand, you ask the model to first recall or invent sim…

You are solving a problem using analogical reasoning.

STEP 1: Before solving the problem below, recall or generate 2 related problems that share a similar underlying structure or reasoning pattern. For each one, briefly state the problem and how it would be solved.

STEP 2: Identify what reasoning approach or pattern those examples have in common.

STEP 3: Apply that same reasoning approach to solve the actual problem below. Show your work step by step.

ACTUAL PROBLEM:
[YOUR QUESTION OR PROBLEM HERE]

OUTPUT FORMAT:
- Related Examples: (2 short examples with solutions)
- Shared Pattern: (1-2 sentences)
- Final Answer: (clearly labeled, with step-by-step reasoning for the actual problem)

Make this prompt yours

Prompt Fundamentals & Techniques

AI Prompt for Multi-Persona Debate to Stress-Test an Idea

Multi persona debate prompting is a technique where you ask a model to argue a decision or idea from several distinct, opposing viewpoints b…

You are facilitating a structured debate between multiple expert personas to help evaluate a decision.

DECISION TO EVALUATE:
[DESCRIBE THE DECISION OR IDEA, e.g. "Should we raise our subscription price by 20% for new customers?"]

CONTEXT:
[RELEVANT BACKGROUND: company size, current numbers, constraints, timeline]

PERSONAS:
1. [PERSONA 1 β€” e.g. "Risk-Averse CFO who prioritizes cash flow stability and customer retention"]
2. [PERSONA 2 β€” e.g. "Aggressive Growth Lead who prioritizes revenue growth and market share"]
3. [PERSONA 3 β€” e.g. "Customer Success Manager who prioritizes existing customer satisfaction"]

TASK:
1. Have each persona give a 2-3 sentence opening argument from their specific incentive and priorities
2. Run one round of rebuttal where each persona directly challenges at least one point from another persona
3. After the debate, provide a neutral synthesis that lists the strongest point from each side
4. End with a short, clearly labeled recommendation and the key risk to monitor if that recommendation is followed

CONSTRAINTS:
- Keep each persona's arguments distinct and grounded in their stated priorities, not generic pros/cons
- Do not let the synthesis simply average the positions β€” it should make an actual call
- Flag any assumption the personas are relying on that isn't confirmed in the context provided

OUTPUT FORMAT:
Label each section clearly: Opening Arguments, Rebuttals, Synthesis, Recommendation.

Make this prompt yours

Prompt Fundamentals & Techniques

AI Prompt for Step-Back Prompting to Improve Reasoning Accuracy

Step back prompting is a technique for getting more accurate answers from ChatGPT, Claude, or Gemini by asking the model to first state the…

ROLE: You are a careful reasoning assistant that solves problems by first identifying general principles.

TASK: Answer the following specific question: [SPECIFIC QUESTION OR PROBLEM]

CONSTRAINTS:
1. Before answering, state the general principle, rule, or concept that applies to this type of problem. Write this as a standalone statement that would be true for any similar problem, not just this one.
2. Then explain how that general principle applies to the specific details given.
3. Only after steps 1 and 2, give your final answer.
4. If your final answer seems to contradict the general principle you stated, flag the contradiction and revise instead of ignoring it.

OUTPUT FORMAT:
General Principle: [the abstracted rule]
Application: [how the rule applies to this specific case]
Final Answer: [the specific answer]

DOMAIN CONTEXT: [OPTIONAL: SUBJECT AREA, E.G. PHYSICS, TAX LAW, SOFTWARE DEBUGGING]

Make this prompt yours