A model-produced function argument is untrusted input. Validate it against a narrow schema, then authorize the requested action against the signed-in user and the current business state. A valid JSON object does not prove that the user intended its effect.
Function calling gives an application structured arguments for a declared tool. OpenAI documents that the application supplies the tools and executes the call; it does not make the model an authorization system. OWASP's prompt-injection guidance also identifies unauthorized functions as a possible consequence when untrusted text influences a model.
Use three gates, in this order
| Gate | Question | Example failure it catches |
|---|---|---|
| Schema | Is the shape and range acceptable? | A negative refund amount or an extra destination_account field |
| Authorization | May this actor perform this operation on this resource? | A support user asks to refund an order from another tenant |
| Confirmation | Does a person approve a consequential effect now? | A model proposes a bulk refund after reading hostile ticket text |
Do not merge the gates. A JSON Schema can restrict amount_cents to an integer from 1 to 50,000. It cannot establish that the order belongs to the customer in the current session. An access-control check can establish that relationship. It cannot establish that a human reviewed a transfer that has an unusual business effect.
A worked refund example
Assume a SaaS support agent has a create_refund tool. Keep its public model-facing definition small:
{"order_id":"string","amount_cents":"integer","reason":"duplicate|service_failure"}When the model proposes a call, the application should parse it with a schema that rejects unknown fields, load the order server-side, and use the authenticated support identity rather than a model-provided tenant ID. It should compare the amount with the remaining refundable amount. For a large amount or a refund outside the normal support role, save a review record and ask an authorized person to confirm.
The OpenAI function-calling guide recommends strict schemas for structured function arguments. Strictness improves consistency, but it does not remove the need for these application checks. Treat the tool definition as an interface contract, not as a permission grant.
Design arguments that are hard to misuse
Prefer opaque resource IDs over free-form selectors. Use enumerations for irreversible choices. Set maximum list lengths and string lengths. Derive tenant, currency, operator identity and destination from trusted server-side state. Return a read-only preview before an action that changes money, access, records or external systems.
Avoid a general tool such as run_sql(query) or send_http_request(url, body) when a narrow operation can serve the workflow. A get_invoice_status(invoice_id) tool gives the model less authority and a smaller validation surface than a database client. Least privilege also makes tests more meaningful: a rejected invalid call proves something only if the tool cannot escape through a more general path.
Test the failures that look valid
Include adversarial tool-call tests in the same suite as normal assistant tests:
- A retrieved document asks the model to refund every order.
- A valid order ID belongs to a different organization.
- The amount exceeds the unrefunded balance.
- A JSON object includes an unknown field that a future implementation might accidentally honor.
- A duplicate request arrives after a timeout.
Record the proposed tool name, schema verdict, authorization verdict and confirmation result. Do not record full prompts or credentials by default. Alectura can check model-output tool calls against an allowlist, denylist and argument JSON Schema, but it is an inference gateway, not a tool gateway. Your application still performs identity checks and executes the tool. Start with one non-production policy through the quickstart, then test the exact tools your product exposes.
Decide how to fail
Schema and authorization failures should return a safe, specific application error to the model, such as “order is not available to this session.” Do not reflect untrusted argument text. A tool-policy detector may add another signal, but OWASP notes that prompt injection has no foolproof prevention; it must not be the only barrier between generated text and a side effect.
If the model or a detector is unavailable, decide per tool whether the safe behavior is to defer, return a read-only result, or stop. Write that choice down next to the tool definition. A refund, an export and an email each need a different recovery path.
