This prompt template is designed for agent developers and platform engineers who need to recover structured function calls when a model outputs natural language prose instead of a valid JSON tool call. The core job-to-be-done is intent extraction: taking a user's or sub-agent's free-text request (e.g., 'send an email to Priya about the Q3 report') and mapping it to the correct tool name and a valid set of arguments from the available tool registry. The ideal user is an engineer building an agent loop that cannot afford to abort execution on a format error and needs a reliable repair step before retrying the tool call.
Prompt
Function Call Repair from Natural Language Fallback Prompt Template

When to Use This Prompt
Define the job, reader, and constraints for converting natural language tool invocations into structured function calls.
Use this prompt when the model's primary output is a natural language description of an action rather than a structured function call, and you have access to the original tool schema and invocation context. This is common with models that lack native function-calling support, when using cheaper models for cost optimization, or when a model 'thinks aloud' before acting. Do not use this prompt when the model has already produced valid JSON that merely fails a business rule—use a schema-mismatch or type-coercion repair prompt instead. Also avoid this prompt when the natural language request is genuinely ambiguous and requires user clarification rather than automated inference; escalating to a human is safer than hallucinating arguments.
The prompt requires the original natural language utterance, the list of available tools with their schemas, and the conversation context. It outputs a structured function call with an extracted tool name and arguments. Before shipping, you must wire in validation against the tool schema, set a retry budget, and add an eval that checks for argument hallucination—specifically, that no argument value was invented without grounding in the input text. Start by copying the template below, substituting your tool registry and input, then build the harness described in the implementation section.
Use Case Fit
Where this prompt works, where it fails, and the operational conditions required before you wire it into an agent loop.
Good Fit: Prose-to-JSON Recovery
Use when: the model outputs natural language describing a tool call instead of a structured function call. This prompt extracts the intent, tool name, and arguments from free text. Guardrail: always validate the repaired JSON against the tool schema before execution.
Bad Fit: Syntax-Only JSON Breaks
Avoid when: the model output is already valid JSON but contains schema violations like wrong types or missing fields. Use a schema-mismatch repair prompt instead. Guardrail: route to the correct repair path based on whether the failure is structural (this prompt) or semantic (field correction prompt).
Required Input: Original User Message
Risk: without the original user message, the repair prompt cannot distinguish between user intent and model hallucination. Guardrail: always pass the full user message as context so argument inference is grounded in what the user actually requested, not what the model imagined.
Required Input: Tool Schema
Risk: repairing arguments without the tool schema leads to hallucinated parameter names and invalid enum values. Guardrail: pass the complete function definition, including parameter types, required fields, and enum constraints, so the repair prompt can produce schema-compliant output.
Operational Risk: Intent Drift
Risk: the repair prompt may reinterpret the user's intent during extraction, producing a valid tool call that does something different from what the user asked. Guardrail: run an intent-preservation eval comparing the repaired call against the original user message before executing the tool.
Operational Risk: Argument Hallucination
Risk: when the natural language fallback is vague, the repair prompt may invent specific argument values not present in the original text. Guardrail: flag any argument value that cannot be traced back to the user message or conversation context, and escalate for human review if confidence is low.
Copy-Ready Prompt Template
A reusable prompt for converting natural language tool invocations into structured function calls when the model outputs prose instead of JSON.
This prompt template is designed to recover from a common agent failure mode: the model describes what it wants to do in natural language instead of emitting a valid function call. Use this template when your agent loop receives a text response that contains an implied tool invocation but no structured JSON. The prompt instructs the model to extract the intended tool name, arguments, and any clarifying questions from the free text, then output a clean, schema-conformant function call. It is not a replacement for proper tool-use fine-tuning or system prompt design—it is a repair step for production fallback.
textYou are a function call repair agent. Your job is to convert a natural language description of a tool invocation into a valid structured function call. ## INPUT Natural language agent response: """ [INPUT_TEXT] """ ## AVAILABLE TOOLS [TOOLS] ## CONSTRAINTS - Output ONLY a valid JSON object with the following structure. No markdown, no commentary. - If the input describes a tool that does not match any available tool, set `tool_name` to `null` and explain the mismatch in `clarification`. - If arguments are missing or ambiguous, set them to `null` and list what is needed in `clarification`. - Do not invent argument values that are not present in the input text. - Preserve the user's intent exactly. Do not add, remove, or reinterpret actions. ## OUTPUT SCHEMA { "tool_name": "string | null", "arguments": {}, "clarification": "string | null", "confidence": "high | medium | low" } ## EXAMPLES [EXAMPLES] ## RISK LEVEL [RISK_LEVEL]
To adapt this template, replace each square-bracket placeholder with production data. [INPUT_TEXT] should contain the raw natural language response from the model. [TOOLS] must include the full function definitions—names, descriptions, and parameter schemas—exactly as they were provided in the original request. [EXAMPLES] should contain at least two few-shot demonstrations: one showing a straightforward extraction and one showing an ambiguous or missing-tool case. Set [RISK_LEVEL] to high if the tool performs destructive actions (delete, send, charge) so downstream code can enforce human approval. After the prompt returns, validate the output against the schema before executing any tool. If confidence is low or clarification is populated, route to a human or a clarification step rather than proceeding automatically.
Prompt Variables
Required inputs for the Function Call Repair from Natural Language Fallback prompt. Each placeholder must be populated before the repair prompt is sent. Missing or malformed inputs are the most common cause of repair failure.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[NATURAL_LANGUAGE_INVOCATION] | The raw natural language text the model output instead of a structured function call. This is the input to be repaired. | "Hey can you look up the order status for customer ID 84921 from last Tuesday?" | Must be non-empty string. Check for null, whitespace-only, or token-truncated inputs. If truncated, route to Truncated Output Recovery instead. |
[AVAILABLE_TOOLS_SCHEMA] | The full tool definitions the model should have used, including function names, descriptions, and parameter schemas. Used to match intent to the correct tool. | {"type":"function","function":{"name":"get_order_status","parameters":{"type":"object","properties":{"customer_id":{"type":"string"},"date_range_start":{"type":"string","format":"date"}}}}}} | Must be valid JSON matching the tool schema format used by the target model provider. Validate with JSON.parse before insertion. Include only tools available in the current agent context to prevent hallucinated tool selection. |
[CONVERSATION_CONTEXT] | The preceding conversation turns that provide context for the natural language invocation. Helps disambiguate intent and infer missing arguments. | "User: I need to check on an order. Assistant: Sure, which order? User: The one from last Tuesday." | Optional but strongly recommended. If null, repair quality degrades for ambiguous invocations. Truncate to last N turns to stay within context budget. Strip any PII not relevant to the repair task. |
[VALIDATION_ERROR_MESSAGE] | The specific error returned when the original output failed tool call validation. Guides targeted repair of the actual failure. | "Missing required parameter: customer_id. Expected type: string." | Must be the exact error string from the validator. Do not paraphrase. If no prior validation was attempted, set to null and the prompt will perform initial extraction without error-guided repair. |
[REPAIR_STRATEGY] | Controls how aggressive the repair should be: infer missing arguments from context, request clarification, or escalate to human. | "infer_from_context" | Must be one of: "infer_from_context", "request_clarification", "escalate_to_human", or "conservative_infer". "conservative_infer" infers only when confidence is high. Validate against allowed enum before prompt assembly. |
[RETRY_BUDGET_REMAINING] | Number of remaining repair attempts in the current agent loop. Adjusts repair strategy: aggressive inference on early retries, conservative on final attempts. | 2 | Must be a non-negative integer. If 0, the prompt should produce an escalation output rather than another repair attempt. Validate type before insertion. Default to 3 if not tracked. |
[OUTPUT_SCHEMA] | The expected structure for the repaired function call output. Defines the fields the repair prompt must return. | {"tool_name":"string","arguments":"object","confidence":"number","repair_notes":"string"} | Must be valid JSON Schema or a structured output format supported by the target model. Include confidence field for downstream gating. Validate schema parseability before prompt assembly. |
Implementation Harness Notes
How to wire the natural language fallback repair prompt into an agent loop with validation, retries, and observability.
This prompt is designed as a recovery step inside an agent execution loop, not as a standalone endpoint. It should be invoked only after a primary function-calling attempt has failed—specifically when the model returns unstructured prose instead of a valid tool call JSON. The harness must first detect this failure mode by checking whether the model's output is parseable JSON matching a known tool schema. If the output is valid JSON but fails schema validation, route to a structured repair prompt (such as Malformed Tool Call JSON Repair) instead. This prompt is exclusively for the prose-to-structured conversion path.
Wire the prompt into your agent framework as a conditional branch. After the primary model invocation, run a lightweight classifier or regex check: if the response contains no JSON block or the JSON parser throws, extract the full text response and pass it as [NATURAL_LANGUAGE_INPUT]. Supply the [TOOL_REGISTRY] as a list of available tool names with brief descriptions—do not include full schemas here, as the goal is disambiguation and intent extraction, not schema validation. The [CONVERSATION_CONTEXT] should include the last 2-3 user and assistant turns to ground the repair. Set a strict retry budget: this prompt should run at most once per turn. If it fails again, escalate to a human or log the failure for offline analysis rather than looping indefinitely.
For validation, parse the repaired output and run it through the same tool call validator used in your primary path. Check that the tool_name matches an entry in your registry exactly (case-sensitive comparison). Validate that all required arguments for that tool are present and correctly typed. Log every repair attempt with: the original prose text, the repaired JSON, whether validation passed, and the tool name extracted. This audit trail is critical for detecting systemic failure patterns—such as a model consistently failing to call a specific tool—and for tuning the primary prompt to reduce fallback frequency. If your application operates in a regulated domain, require human approval before executing any repaired tool call, and surface both the original prose and the repair in the review UI.
Expected Output Contract
Define the exact shape, types, and validation rules for the repaired function call output. Use this contract to build a parser that rejects invalid repairs before they reach the tool execution layer.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
tool_name | string | Must match exactly one tool name from the provided [TOOL_REGISTRY] using case-sensitive comparison. Reject if no exact match exists. | |
arguments | object | Must be a valid JSON object. Parse check required. Reject if unparseable, an array, or a primitive. Must not contain keys absent from the target tool's parameter schema. | |
arguments.*.value | varies per schema | Each argument value must satisfy the type constraint defined in [TOOL_SCHEMA] for that parameter. Reject on type mismatch after coercion attempt fails. | |
arguments.*.required_fields | varies per schema | All parameters marked as required in [TOOL_SCHEMA] must be present. Reject if any required parameter is missing and cannot be inferred from [CONVERSATION_CONTEXT]. | |
repair_notes | string or null | If present, must be a string no longer than 200 characters summarizing what was changed from the original malformed call. Null allowed. Reject if present but empty string. | |
confidence_score | number | If present, must be a float between 0.0 and 1.0 inclusive representing repair confidence. Reject if outside range or non-numeric. Null allowed. | |
original_error | string | If present, must be a string containing the validation error message from [ERROR_CONTEXT] that triggered the repair. Used for audit trail. Reject if present but does not match a known error pattern. | |
escalation_required | boolean | Must be true if any required argument could not be repaired or if confidence_score is below [CONFIDENCE_THRESHOLD]. Must be false otherwise. Reject if boolean value contradicts repair completeness. |
Common Failure Modes
When converting natural language to function calls, these are the most common production failure patterns and how to prevent them.
Hallucinated Tool Names
What to watch: The model invents a tool name that doesn't exist in the registry, often by blending two real tool names or guessing a plausible-sounding function. Guardrail: Always validate the extracted tool name against the available tool list before execution. Use fuzzy matching with a confidence threshold and escalate to clarification when no match exceeds 0.85 similarity.
Fabricated Arguments from Conversation Context
What to watch: The model infers required arguments from prior conversation turns rather than the user's actual intent, filling in plausible but incorrect values for missing parameters. Guardrail: Diff extracted arguments against explicitly stated user inputs. Flag any argument not directly grounded in the current request for confirmation before execution.
Intent Drift During Extraction
What to watch: The repair prompt changes the user's intended action while converting prose to structured JSON—turning a read operation into a write, or a query into a deletion. Guardrail: Run an intent-preservation eval comparing the extracted function call against the original natural language input. Require human approval when the action verb or target resource changes.
Enum Value Mismatch After Normalization
What to watch: The model normalizes an enum value to something semantically similar but not in the allowed set—mapping 'high priority' to 'urgent' when the schema only accepts 'low', 'medium', 'critical'. Guardrail: Validate every enum argument against the tool schema's allowed values. Log near-misses for schema improvement and return a clarification request with the valid options listed.
Missing Required Parameters Without Defaults
What to watch: The extracted function call omits a required parameter that has no sensible default, producing a call that will fail at the API layer. Guardrail: Schema-validate the repaired call before execution. For missing required fields, attempt context-grounded inference only on the first retry; escalate to user clarification on the second attempt.
Retry Loop Exhaustion with Degraded Repairs
What to watch: Each repair attempt degrades quality as the model loses context or overcorrects, eventually producing a valid-but-wrong function call that passes schema checks. Guardrail: Cap retries at 3 attempts. On the final retry, include the original user input verbatim and require the repair to cite which part of the input supports each argument value.
Evaluation Rubric
Criteria for evaluating whether a repaired function call correctly preserves intent, matches the tool schema, and avoids hallucinated arguments before the repaired call is executed in production.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Intent Preservation | The repaired tool name and arguments reflect the same action and entities as the original natural language fallback | The repair selects a different tool or changes the core action (e.g., 'cancel' becomes 'update') | Compare extracted intent labels between original text and repaired call using LLM-as-judge with pairwise preference |
Tool Name Correctness | The repaired tool name exactly matches an available tool in the provided registry | The tool name is misspelled, aliased without mapping, or references a non-existent tool | Exact string match against the tool registry; fuzzy match score must be 1.0 for pass |
Required Argument Completeness | All required parameters from the tool schema are present and non-null in the repaired call | A required parameter is missing, null, or empty string when schema requires a value | Schema-aware field presence check: iterate required fields and assert presence with non-null value |
Argument Type Conformance | Every argument value matches the expected type from the tool schema (string, number, boolean, array, object) | A value is the wrong type (e.g., string '123' where number expected) and would fail JSON Schema validation | Run repaired arguments through JSON Schema validator using the tool's parameter schema; zero type errors allowed |
No Hallucinated Parameters | The repaired call contains only parameters defined in the tool schema | Extra parameters not present in the schema appear in the repaired call | Diff the argument keys against the schema's property list; any extra key is a failure |
Enum Value Validity | All enum-constrained arguments contain values from the allowed enum list | An enum argument contains a value not in the allowed list, including case mismatches or synonyms not normalized | Validate each enum argument against the schema's enum array; case-sensitive exact match required |
Context Grounding | Inferred argument values are traceable to the original natural language text or conversation context | A value appears in the repaired call that has no basis in the original text or context | For each inferred argument, require a citation span from the original text; flag any value without grounding |
Structural Validity | The repaired call is valid JSON that can be parsed and matches the tool's overall input schema | The output is malformed JSON, has trailing commas, or fails top-level schema validation | JSON.parse success plus full JSON Schema validation against the tool's input schema definition |
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
Use the base prompt with a single model call and minimal validation. Focus on extracting intent, tool name, and arguments from the natural language fallback. Accept the first repair attempt without retry logic.
codeSYSTEM: You are a function call repair agent. Given a user's natural language request and a list of available tools, extract the intended tool name and arguments as JSON. USER REQUEST: [NATURAL_LANGUAGE_FALLBACK] AVAILABLE TOOLS: [TOOL_SCHEMAS] Return ONLY valid JSON with "tool_name" and "arguments" keys.
Watch for
- Missing schema checks leading to hallucinated parameter names
- Overly broad instructions causing the model to invent tools not in the registry
- No confidence scoring, so bad repairs silently pass through

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