Machine Learning pathway increased my salary by 40%
Function Calling & Tool-Use Engineering
Give models tools without giving away control: schema design, execution sandboxes, authorisation, idempotency and the failure handling that keeps autonomous actions safe.
Executive Overview
Function calling lets a model request an action — search, database query, ticket creation, payment — and receive the result before continuing. The engineering problem is not the model’s ability to emit a call but the system’s ability to constrain what a call can do. Production tool use requires schemas precise enough to validate arguments, tools scoped to the minimum permission needed for the task, execution in a sandbox with timeouts and rate limits, idempotency keys so retries do not duplicate side effects, and result formats that give the model enough information to decide the next step without exposing sensitive data. The dominant failure modes are over-broad tools, unvalidated arguments reaching privileged systems, and retry loops that repeat irreversible actions.
Why It Matters in 2026
Tools convert language model output into consequences in real systems. That is where the value is, and where the risk concentrates. A model that can read is a summariser; a model that can write has blast radius. Teams that design tools with least privilege, strict validation and idempotent execution gain automation that is auditable and bounded; teams that expose broad internal APIs to a model discover the consequences through incidents.
Enterprise Relevance: Tool use is how AI moves from answering to acting. Every tool is an API surface exposed to a probabilistic caller, so the security and reliability discipline of API design applies with less predictable inputs.
Learning Outcomes
- Design tool schemas that make invalid arguments impossible
- Scope tools to least privilege and bind them to user entitlements
- Execute tools in sandboxes with timeouts and idempotency
- Design bounded tool results that guide the next step
- Test tool use against injection and retry duplication
Tool Schema Precision
Schemas must constrain types, enumerations, ranges and required fields, and reject ambiguity. A parameter described in prose is a suggestion; a parameter constrained by schema is validated before execution.
Least-Privilege Scoping
Each tool should do one thing with the narrowest permission that satisfies it. A general "query database" tool invites both injection and accidental scope creep; a parameterised read-only tool does not.
Sandboxed Execution
Tools run with timeouts, rate limits, resource caps and network egress rules. Execution happens in a service boundary the model cannot reconfigure.
Idempotency
Retries are normal in agentic systems. Side-effecting tools must accept an idempotency key so repeated calls with the same intent produce one effect, not several.
Result Design
Tool results are prompts. Structured, bounded, summarised results keep the model on task, while unbounded payloads waste context and can leak data the task did not require.
Architecture & Design
A tool-use architecture puts a gateway between the model and every system it can affect. The gateway validates arguments against the schema, checks the caller’s entitlement for that specific action, enforces rate and concurrency limits, executes in a sandbox and returns a bounded result, logging every invocation with the model, arguments and outcome.
Architecture Layers
Reference Architectures
Technology Stack
| Layer | Options | What to decide |
|---|---|---|
| Tool definition | JSON Schema, OpenAPI, provider-native formats | Whether tools are reusable across models |
| Protocol | MCP, custom HTTP, gRPC | How many applications must share the tools |
| Execution | Container sandbox, serverless functions, queue workers | Timeout and resource limits per tool |
| Policy | Policy engine, application logic | Where authorisation decisions are enforced |
| Audit | Structured logs, OpenTelemetry, SIEM | Retention and review cadence for tool calls |
Engineering Workflow
Why broad tools fail audits
A tool that accepts arbitrary SQL or arbitrary URLs is effectively a remote shell with extra steps. Auditors and security reviewers treat it as such. Narrow, purpose-built tools with enumerated parameters produce call logs that can be reviewed, and they make the blast radius of a compromised model response small enough to reason about.
Designing results the model can use
Tool results shape the next decision. Return structured fields with explicit status, truncated lists with counts, and error codes the model can branch on. Never return a raw dump: it consumes context, dilutes attention and may disclose fields the task never needed. Errors should distinguish retryable failures from permanent ones so the model does not loop.
Operating model for Function Calling & Tool-Use Engineering
Making function calling & tool-use engineering work over time is an ownership question before it is a tooling question. Someone must hold the quality bar, someone must own the artefacts and someone must own the operational signals. In practice that means a named owner per workflow, a repository location that is the single source of truth, and a review path where changes arrive with evidence attached rather than assertion. The capabilities that matter most in this discipline — tool schema design, argument validation, sandboxed execution — are learned by doing them on real traffic, so the operating model should create a steady cadence of small changes rather than occasional large ones. Teams that centralise everything in a specialist group create a bottleneck; teams that distribute without shared standards create drift. The workable middle is a platform that provides the shared harness and gates, with product teams owning behaviour and outcomes.
Measurement plan for Function Calling & Tool-Use Engineering
A measurement plan turns function calling & tool-use engineering from a matter of opinion into a managed process. Start with the outcomes the business already cares about — cost per completed task, handling time, error rates — and attach the engineering signals that lead them: tool call success rate, argument validation failure rate, calls per task. Establish a baseline before changing anything, because without it improvement cannot be distinguished from noise. Segment by tenant, document type or intent where behaviour genuinely differs, since averages hide the failures that matter. Set thresholds that block rather than warn, review them quarterly as the system and traffic change, and record the reason whenever a threshold is adjusted. The plan is finished when a new engineer can read it, run the harness and reach the same conclusion the team would.
Working with providers and platforms on Function Calling & Tool-Use Engineering
No team owns this discipline alone: model providers, infrastructure platforms and internal review functions all shape what is possible. The practical work is to define the contract with each. From providers you need change notification, evaluation access and documented behaviour at the versions you actually run, so that an upgrade is a planned event rather than a surprise. From the platform you need the shared capabilities this topic depends on — logging, flags, secret management, queueing — so that product teams do not rebuild them inconsistently. From risk and audit you need agreement on the evidence that will be requested, captured at the point where it is generated. Negotiate these once and write them down. Teams that skip this step spend their time in repeated explanations of behaviour they cannot evidence, and they absorb provider changes as incidents rather than as planned migrations.
Bringing the team with you
Practice changes fail quietly when they are imposed as process. The teams that sustain function calling & tool-use engineering explain why the gate exists, show the incident it would have prevented, and make the fast path the compliant path. That means templates that already include the artefact, a harness that runs in one command, and a dashboard that answers the question people ask first: is it getting worse? When the tooling makes the right thing easy, adoption follows; when it adds a step with no visible benefit, it is bypassed at the first deadline. Budget time for the first two workflows explicitly, because that is where the habit forms, and treat a caught regression as a success rather than a defect. A team that has experienced one early catch rarely needs persuading again.
Failure modes to design out
Most incidents in this area trace to a small set of predictable design gaps: privilege escalation through tools; duplicate side effects on retry; runaway execution cost. Each has a structural remedy rather than a procedural one. Where the risk is silent drift, the remedy is a gate that fails loudly. Where the risk is uncontrolled blast radius, the remedy is narrower scope and a rollback path that has been tested. Where the risk is unowned quality, the remedy is a named owner with time allocated. Designing these out at the start costs a fraction of discovering them in production, and it converts the team's attention from firefighting to improvement. The test of a design is whether a plausible mistake by a competent engineer produces a caught error rather than a customer-visible incident.
Tool Risk Classes
| Class | Examples | Controls |
|---|---|---|
| Read-only, scoped | Document lookup, status query | Schema validation, entitlement filter, rate limit |
| Read-only, broad | Search across corpora | Result bounding, field redaction, query logging |
| Side-effecting, reversible | Draft creation, ticket update | Idempotency key, confirmation for bulk actions |
| Side-effecting, irreversible | Payment, deletion, external message | Human confirmation, dual control, strict scoping |
Maturity Levels — Function Calling & Tool-Use Engineering
| Level | Characteristics | Evidence you would see |
|---|---|---|
| Ad hoc | Practice depends on individual judgement; changes are unreviewed | No baseline metrics, incidents explained by anecdote |
| Defined | Artefacts are versioned and tool schema design is applied consistently | Repository contains versioned artefacts and a documented process |
| Measured | Tool call success rate and related signals are tracked per workflow | Dashboards and baselines exist, regressions are detected before users |
| Managed | Thresholds gate releases and ownership is explicit | Changes blocked on evidence, incidents reviewed with recorded actions |
Enterprise Use Cases
Case Study: Duplicate refunds from retries
Case Study: Over-broad query tool
Implementation Steps
Practical Project
Operationalise Function Calling & Tool-Use Engineering
Take an existing workflow that relies on function calling & tool-use engineering and make its behaviour measurable, gated and reversible, without changing the product surface users see.
Requirements
- A versioned artefact set: configuration, prompts or schemas, and the evaluation dataset
- Baseline measurements for quality, latency and cost before any change
- A release gate that blocks regressions rather than warning about them
- Documentation sufficient for another engineer to reproduce the evaluation
- A rollback procedure tested once before it is needed
Steps
- 1.Map the current workflow and identify the decision points where quality can be measured
- 2.Capture baseline metrics on live traffic samples and store them with the release record
- 3.Build or extend the evaluation dataset with edge cases drawn from real incidents
- 4.Implement the change behind a flag and run the evaluation harness against it
- 5.Roll out to a small cohort, compare against baseline and revert or proceed on evidence
- 6.Record the outcome and update the playbook with what the evaluation revealed
Enterprise & GCC Applications
- Global capability centres use Function Calling & Tool-Use Engineering to standardise engineering practice across distributed teams, with shared evaluation and release gates rather than per-site conventions.
- Enterprise architecture groups apply the topic when defining reference platforms, so product teams inherit compliant defaults instead of rebuilding controls per project.
- Delivery leadership uses the associated metrics in quarterly reviews, replacing anecdotal quality claims with measured evaluation coverage and regression escape rates.
- Risk and audit functions rely on the artefacts the practice produces — versioned prompts, evaluation results, decision logs — as evidence during internal and external review.
Risks & Mitigations
Key Metrics
Trends & 2026 Outlook
Standardised tool protocols such as MCP
Human confirmation for irreversible actions
Policy engines for agent actions
Tool-level cost and rate governance
Career Roles
Frequently Asked Questions
How many tools should one agent have?
As few as the task needs. Large tool sets increase selection errors and expand the attack surface. Route between smaller specialised agents rather than giving one agent every tool.
Should the model choose tools or should we orchestrate?
Use deterministic orchestration for known workflows and let the model choose only where the path genuinely varies. Predictability is cheaper to test and operate.
How do we prevent prompt injection from triggering tools?
Validate arguments, scope tools narrowly, require confirmation for irreversible actions and never let untrusted content define a tool call directly.
What belongs in an audit log for tool use?
Requesting user, tool, validated arguments, decision rationale where available, outcome, latency and model version, retained under the organisation’s audit policy.
Are tool calls expensive?
They consume tokens for schemas and results and add latency per round trip. Keep schemas compact and results bounded to control both.
How do we test tool use?
With scripted scenarios covering valid calls, invalid arguments, permission denials, timeouts and retries, plus adversarial attempts to escalate scope.
What does a mature function calling & tool-use engineering practice look like?
It looks unremarkable: artefacts are versioned, changes arrive with evaluation evidence, thresholds block regressions, and a named owner reviews the metrics on a regular cadence. The visible behaviour is small frequent releases rather than occasional large ones, because small changes are what make attribution possible.
How do we start in an existing codebase without a rewrite?
Pick one workflow, instrument its baseline, and build a small evaluation set from real traffic and past incidents. Gate that single workflow first. Once the pattern is proven, extend it — retrofitting a whole estate at once usually stalls, while one gated workflow establishes the habit and the tooling.
What should we measure in the first thirty days?
Only what you can act on: a baseline for the workflow you chose, the leading signals that predict the outcome you care about, and the cost of running the current design. Resist adding dashboards nobody reads. Thirty days is enough to establish one gated workflow, one baseline and one caught regression, which is a stronger position than a broad but unmaintained measurement programme.
Which decisions belong in the platform rather than in each product team?
Anything that must be identical across the estate to be auditable: logging and trace format, secret handling, evaluation harness interfaces, flag mechanics and rollback paths. Behavioural decisions — what the system should do, what quality bar applies, which cases are unacceptable — belong with the product team that owns the outcome.
References & Resources
- Provider function calling documentation:Schema formats, parallel calls and result handling per model family
- Model Context Protocol specification:Standard interface for exposing tools to AI applications
- API security guidance:Authentication, authorisation and input validation practice applied to tools
- OWASP Top 10 for LLM Applications:Excessive agency and insecure output handling as tool-use risks
Continue this lesson with a subscription
AI Engineering & AI-Native Software Development is part of the paid catalogue. You have read the free preview. A subscription opens the rest of this lesson, the classroom slides and the assessment questions.
- The full lesson for this topic and every other catalogue topic
- Every classroom slide deck and worked example
- All assessments, with a verifiable certificate on completion
The Free-To-Learn library stays open to everyone and is not affected by this.
