Back to cookbook

ChatGPT Prompt for Reliable Function and Tool Calling

❀️1
2 views Updated
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

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.

Example input

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.

Example output

Step 1: This question asks about current weather conditions, which I cannot answer from the conversation alone β€” I don't have real-time weather data.

Step 2: The best-fit tool is get_weather.

Step 3: Required argument for get_weather is city. The user has not specified a city anywhere in this conversation, so this value is missing.

Step 4: I need to ask the user for the missing argument before calling the tool.

Response to user: "Happy to check that β€” which city are you asking about?"

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