Sub topic 3
Tool Use, Uncertainty, and Prompt Maintenance
Assume you can call an LLM chat API, read JSON, and follow basic Python. This chapter focuses on instructions around tools and prompt quality.
Instruct the Model on Tool Use
A tool instruction should define:
- What the tool does.
- Its input schema and required fields.
- When the model may call it.
- When it must ask for confirmation.
- What to do when the tool fails.
- Whether the tool result is trusted data or an instruction.
TOOLS = [{
"name": "lookup_invoice",
"description": "Find an invoice by its exact invoice ID.",
"parameters": {
"type": "object",
"properties": {"invoice_id": {"type": "string"}},
"required": ["invoice_id"],
"additionalProperties": False,
},
}]
SYSTEM_RULE = (
"Call lookup_invoice only when the user provides an invoice ID. "
"Never invent an ID. If the tool fails, explain the failure and ask the user "
"to retry; do not guess the result."
)Use confirmation before actions with external effects, such as sending email, changing data, or making a purchase.
Guide Reasoning and Handle Uncertainty
Ask the model to perform useful checks without requesting private chain-of-thought. For example: “Verify that the answer is supported by the documents. If evidence is missing, say that you are uncertain and state what information is needed.”
Specify an allowed fallback. “I do not know” is safer than a confident invention.
Test Prompts with a Small Evaluation Set
Keep examples for normal requests, missing data, malicious document text, invalid tool arguments, and tool failures. Check observable properties such as valid JSON, no unsupported claims, and confirmation before side effects.
Diagnose and Fix Common Failures
If the model calls a tool too often, tighten the trigger and add a counterexample. If it invents missing values, require a refusal or clarification. If output parsing fails, simplify the schema and validate every response.
Version and Maintain Prompts
Store prompts in source control. Give each prompt a version, changelog entry, and evaluation results. Change one behavior at a time, then rerun the same test set.
Exercise
What should a model do when a required tool argument is missing?
Show answer
Ask the user for the missing argument instead of inventing one or calling the tool with invalid data.