When to reach for it
- External actions or data sources must be integrated in a controlled manner.
- Arguments need strict validation.
- Tool usage should be observable and bounded.
Structured JSON in, typed function call out.
The model emits a structured call — a named function with typed, schema-validated arguments — that the harness executes, feeding the result back into the model's context; the model decides which function to call, when, and with what arguments.
In practiceA calendar assistant uses function calling to invoke a `create_event(title, start, end, attendees)` function with validated arguments, rather than generating a free-text API call the harness must parse.
The model never executes anything. It writes a request in a fixed format, and the harness decides whether and how to carry it out.
1 · Before the run
2 · During the run
| Step | Who | What happens |
|---|---|---|
| 1 | Model | Calls create_event with start "tomorrow 10am" |
| 2 | Harness | Rejects the call: start is not a date-time. The error goes back as the result |
| 3 | Model | Calls again with start 2026-05-13T10:00 and end 11:00 |
| 4 | Harness | The arguments are valid. The function runs and returns the event ID |
| 5 | Model | Answers the user: the review is booked for 13 May, 10:00 to 11:00 |
TOOLS = [{
"name": "create_event",
"description": "Create a calendar event.",
"parameters": {
"type": "object",
"properties": {
"title": {"type": "string"},
"start": {"type": "string", "format": "date-time"},
"end": {"type": "string", "format": "date-time"},
},
"required": ["title", "start", "end"],
},
}]
def run(messages):
while True:
reply = model(messages, tools=TOOLS)
if not reply.tool_calls:
return reply.text # no call: this is the final answer
for call in reply.tool_calls:
try:
# the harness checks, not the model
args = validate(call.arguments, TOOLS)
result = FUNCTIONS[call.name](**args)
except ValidationError as error:
# an error goes back as a result
result = f"Invalid arguments: {error}"
messages += [call, tool_result(call.id, result)]When to reach for it
When it backfires
A tool's argument shape changes; the model keeps emitting the old shape; calls succeed parsing but execute with stale parameters.
Countermeasure
Validate every argument payload against the current schema at the harness, before dispatch. Reject and surface the mismatch — never coerce.
The model invents a plausible id, path, or amount that matches the type and validates cleanly — then the call executes against a record that never existed or the wrong one.
Countermeasure
Validate arguments against real referents (existence and ownership checks), not just types; have the tool reject unknown ids rather than acting on a well-typed guess.
Threat exposure
Adopting this pattern opens these attack surfaces. Each links to its entry in the threat model.
Full threat model →Keep going
Search patterns, frameworks, and pages.