Spring AI tool calling with Spring Boot lets a language model ask your application to run Java methods, such as looking up an appointment or drafting a referral. That is useful and risky in equal measure, because a model that can call a write method can change records based on a misread request.
Startup founders and engineering leaders will find how tool calls flow in Spring AI, how to build an allow-list of tools, why writes need a human step and what to log.
What is Spring AI tool calling with Spring Boot?
Spring AI tool calling with Spring Boot is a pattern where the model requests a named Java method with arguments, and your Spring application decides whether to run it and returns the result. Safe designs expose a short allow-list of tools and route every write through a person before it executes.
Letting a model act inside your application?
We build tool-calling services with allow-lists, approvals and audit logs.
The Spring AI reference states that the application, not the model, owns the tool calling logic: the model can request a tool call and provide input arguments, the application executes the tool and returns the result, and the model never receives direct access to the APIs behind the tools.
That split is the control point. Every tool call passes through code you wrote, so Agnotic Technologies enforces policy there rather than in the prompt.
Why does tool calling need an allow-list?
Tool calling needs an allow-list because the model chooses from whatever it is offered, and anything offered can be chosen for the wrong reason. A short, explicit list per request keeps the reachable actions small.
Spring AI executes only the tools attached to a request unless its resolution fallback setting is enabled, and its documentation warns that enabling the fallback makes every tool the resolver can reach executable whenever the model names it, including destructive ones.
- Per use case: a scheduling assistant gets scheduling tools, not billing or chart tools.
- Per role: the tools offered depend on the signed-in user's permissions, checked again inside each tool.
- Read before write: start with read tools and add write tools one at a time.
- Fallback off: keep resolution limited to tools attached to the request.
How should tools be classified?
| Class | Examples | Execution rule |
|---|---|---|
| Read | Look up an appointment slot, a policy or an order status | Runs automatically after permission checks |
| Draft | Prepare a referral letter or a message for review | Runs automatically, but the output is saved as a draft |
| Write | Book, cancel, update a record or send a message | Pauses for a person to approve the exact arguments |
| Never offered | Delete records, change permissions, bulk updates | Not exposed to the model at all |
Classify tools in code, not in their descriptions. The model reads descriptions; your executor reads the class.
How does the human step before a write work?
The human step works by stopping the tool loop when the model requests a write, showing the proposed action to a person, and running it only after approval.
- Step 1, request: the model returns a tool call for a write tool with its arguments.
- Step 2, hold: your code does not execute it; it stores a pending action with the user, tool, arguments and conversation ID.
- Step 3, show: the interface displays the action in plain language, for example the patient, slot and clinician for a booking.
- Step 4, decide: the person approves, edits or rejects, and edits are re-validated by the tool's own checks.
- Step 5, execute: the approved call runs with the approver recorded, and the result goes back to the conversation.
Spring AI supports this by letting you turn off automatic tool execution and run requested calls yourself through ToolCallingManager. Your code then sits between the request and the write.
Read tools need limits too
Read tools need limits too, because a tool that returns too much data leaks it into the conversation even when nothing is written.
- Scope every read to the signed-in user's permissions, checked inside the tool.
- Return the smallest result that answers the question, such as the next appointment rather than the full history.
- Cap result sizes and page through longer lists.
- Mask identifiers the user does not need to see.
These limits also keep responses fast and the model's context small, which makes its choices easier to follow in the log.
Validating arguments inside each tool
Arguments must be validated inside each tool, because the model can produce well-formed but wrong values. Treat them like input from an untrusted client.
- Identifiers: confirm the patient or record exists and the user may act on it.
- Ranges: dates, quantities and durations fall within allowed limits.
- State: the action is valid now, for example the slot is still free.
- Idempotency: a repeated call with the same key does not create a second booking.
What should be logged for each tool call?
Each tool call should be logged with who asked, what the model requested, what ran and who approved it. That record explains any change the assistant made.
The HIPAA Security Rule audit controls standard, 45 CFR 164.312(b), requires hardware, software or procedural mechanisms that record and examine activity in information systems that contain or use electronic protected health information.
- Request: user, conversation ID, tool name and the arguments the model proposed.
- Decision: automatic, approved, edited or rejected, with the approver and time.
- Execution: final arguments, result and any error.
- Linkage: the record changed, so a change can be traced from the record back to the conversation.
Designing the approval screen
The approval screen decides whether people approve carefully or click through. It should show the action, not the model's reasoning.
- Plain summary: who, what and when, in the words staff use, with the record linked.
- Changed fields: for updates, the current value next to the proposed one.
- One action per approval: no batch approve for writes.
- Clear reject path: a reason field that goes into the log and back to the conversation.
Testing tool calling before release
Testing tool calling means testing the executor's rules, not just whether the model picks the right tool.
- Offer only read tools and confirm no write can run, whatever the prompt says.
- Send prompts that try to trigger a write tool not attached to the request.
- Check every write lands in the approval queue with the exact arguments.
- Replay rejected and edited approvals to confirm only the approved version runs.
Run these tests on every release, because a new tool or a changed default can widen what the model can reach without anyone noticing.
How are tools defined in Spring Boot?
Tools in Spring AI are methods annotated with @Tool, or ToolCallback objects, passed to ChatClient for a single request or set as defaults on the client. That choice decides how wide the allow-list is.
- Per request: pass tools with the call so each request carries only what that user and screen need.
- Defaults: reserve default tools for harmless reads that every request may use.
- Descriptions: write them for the model, short and specific, and never rely on them for security.
- Return values: return only the fields the model needs, not whole records with unrelated patient data.
A worked example: rescheduling an appointment
A worked example: a patient asks the assistant in a clinic's app to move next Tuesday's appointment to later in the week.
- The request carries three tools: find the patient's upcoming appointments, list open slots, and reschedule an appointment.
- The model calls the two read tools, which run at once after checking the appointment belongs to the signed-in patient.
- It then requests the reschedule tool with the appointment ID and a new slot, and the executor holds the call.
- The app shows the patient the old and new times and asks for confirmation, which the patient gives.
- The executor checks the slot is still free, reschedules with an idempotency key, logs the approval and returns the result to the model.
In a staff-facing assistant, the approver would be the staff member, and some write tools might need a second approval from a supervisor.
When should a tool return directly?
A tool should return directly when its output is already the final answer, such as a list of open slots. Return direct sends a tool's result straight to the caller without another pass through the model.
The Spring AI reference notes that when the model requests several tools in one round, results are returned directly only if every tool called has return direct set; otherwise they go back to the model.
- Good fit: a lookup whose result is shown as a table.
- Poor fit: results the model needs to explain or combine.
- Never a substitute for approval: return direct changes where output goes, not whether a write runs.
Prompt injection through tool results
Tool results can carry text the model will read as instructions, for example a free-text note asking it to cancel every appointment. Executor rules are what stop that text from becoming an action.
- Treat text returned by tools as data, and keep write tools behind approval whatever the model asks.
- Strip fields that are not needed for the answer.
- Keep tool results small, so less untrusted text reaches the model.
- Test with records that contain instructions in free-text fields.
What are the common mistakes with Spring AI tool calling?
The common mistakes with Spring AI tool calling come from offering too many tools and letting writes run inside the automatic loop.
- Registering every bean as a tool: the model can reach actions nobody intended.
- Policy in the prompt only: an instruction not to call a tool is not a control.
- Automatic writes: a booking or update runs before anyone sees it.
- Trusting arguments: IDs from the model are used without permission checks.
- Thin logs: nobody can tell which conversation caused a change.
What does tool calling mean for your build plan?
Plan tool calling around the tools and their classes, the approval screen and the log. The model integration is the smaller part.
- List candidate tools and classify each as read, draft, write or never offered.
- Design the approval screen with the people who will approve.
- Define argument checks and idempotency keys for each write tool.
- Agree log retention and who reviews tool activity.
How does Agnotic build tool-calling services?
Agnotic builds Spring Boot services with Spring AI tool calling: classified tools, per-request allow-lists, an approval queue for writes, argument validation and audit logs tied to records.
Let the model propose, let people approve
Tool calling with allow-lists and approvals in your Spring Boot stack.
Related reading on Agnotic
AI agents, approvals and Spring reading.


