CE
CloudEngineerHub
Project & IT Hiring · Intune · Azure
Home
Blog
AI & Jobs
Store
Mock Testing
Logs Analyzer
Log Analyzer
Free Log AnalyzerRCA analyzer · basic analysisFreePremium Log AnalyzerLogLens Pro Suite — workspaceProLogLens Pro Suite — BasicFrom $5 /user/moLogLens Pro Suite — ProfessionalFull rule library · correlationLogLens Pro Suite — EnterpriseCustom rules · API · team
Free Tools
CE
Cloud Engineer Hub

Premium Microsoft Intune & Azure training, real-exam mock tests, an offline log root-cause analyzer, and expert engineering content for IT professionals worldwide.

Platforms

  • AI & Jobs
  • Microsoft Intune
  • Microsoft Azure
  • Mock Tests
  • Store

Tools

  • LogLens RCA Analyzer
  • Verify a Certificate
  • Subnet Calculator
  • Password Generator
  • PowerShell Library
  • Blog
  • Pricing & Plans
  • My Dashboard

Company

  • Project & Hiring
  • About Us
  • FAQ
  • Changelog
  • Contact
  • Privacy Policy
  • Terms & Conditions

© 2026 Cloud Engineer Hub. All rights reserved.

Secure CheckoutRazorpay VerifiedTrusted by 500+ IT Pros
    AI & Jobs/🟣 Advanced AI/Topic 17
    🟣 Advanced AI 17 min readTopic 17 / 20

    Function Calling & Tool Calling in AI

    Function calling is a protocol: you describe available functions with JSON Schema, the model replies with a structured tool_call — a name plus JSON arguments — and your validated backend executes the real work (Microsoft Graph, REST APIs, PowerShell, database queries, ticketing systems) before returning the result. The model never runs anything; it only fills in the form. This topic covers schemas, validation, chained calls and least-privilege execution.

    What you will learn

    • Tool schemas
    • Arguments and validation
    • Microsoft Graph tools
    • REST APIs and databases
    • PowerShell as a tool
    • Ticketing integration

    01What is it?

    Function calling is a protocol, not magic: you describe available functions in JSON Schema (name, description, typed parameters), send that list with the prompt, and the model responds with a structured tool_call — a function name plus JSON arguments — instead of prose. Your code executes the real function (a Graph API request, a REST call, a SQL query) and returns the result to the model, which then writes the final answer. The model never runs anything; it only fills in the form. That is exactly why validation on your side is mandatory: arguments are suggestions from a language model, not guarantees.

    02Why does it matter?

    Tool calling is the bridge between “AI that talks about IT” and “AI that works in IT”. With it, one assistant can query Microsoft Graph for a device’s compliance state, hit a REST endpoint for license status, run a read-only PowerShell diagnostic, look up an error code in a database, and file a ServiceNow ticket — the five integrations that cover most helpdesk workflows. Without it, you copy-paste between the chat window and the admin center; with it, the model orchestrates and your validated tools do the touching.

    03How does it work?

    Round trip in six beats: user asks → the LLM sees tool schemas → the model selects a tool and emits arguments → your backend validates and executes (Graph / REST / PowerShell / SQL / ticketing) → the result string goes back into the conversation as a “tool” message → the LLM produces the final answer, or chains the next tool. Design tips that separate good implementations: keep descriptions crisp (they are prompt content — “Gets an Intune device by device name including compliance state” beats “device stuff”); use strict schemas with enums for anything dangerous; return concise, structured results; and never let one turn chain more tool calls than your budget allows.

    04Architecture

      User: “Is LAP-042 compliant?”
            ↓
      LLM + tool schemas
            ↓  tool_call JSON
      Tool Selection → get_device(name)
            ↓
      API / Function (Graph call)
            ↓  result JSON
      Result → back to LLM
            ↓
      Final Answer: “Compliant ✓ (last sync 09:14)”
    The model picks and fills the form; your validated backend presses the buttons.

    05Real-world example

    A working helpdesk flow: user pastes “LAP-042 gets 0x87D1041C on App X”. The model calls get_error_rule(“0x87D1041C”) → your rule database returns the detection-failure flow; calls get_device(“LAP-042”) → Graph returns the device and app install status; then drafts a ServiceNow incident with cause and next steps. In Microsoft-land the same pattern powers Copilot-style integrations over Graph (mail, Teams, Intune), while PowerShell tools let the agent run read-only scripts like Get-ComputerInfo through a constrained runspace rather than a raw shell.

    06Step-by-step practice

    1. 1

      Write the tool schema

      JSON Schema defines each function: name, description and typed parameters. This schema IS the model’s documentation — invest in it, because selection quality is a direct function of description quality.

    2. 2

      A real tool-schema example

      {"type": "function", "function": { "name": "get_intune_device", "description": "Get an Intune device by device name, including compliance state and last sync time", "parameters": { "type": "object", "properties": { "deviceName": { "type": "string", "description": "Exact device name, e.g. LAP-042" } }, "required": ["deviceName"] } } }

    3. 3

      Register tools in the request

      Send the schemas in the chat/completions call via the “tools” array (tool_choice: “auto”). Keep 3-10 tools per assistant — more than that and selection accuracy falls as schemas crowd the prompt.

    4. 4

      Execute with validation

      The model returns tool_calls[0].function.name and .arguments (a JSON string). Parse, validate types/lengths/enums, check permissions, then execute the real call — a Graph request, REST endpoint, SQL query, or a constrained PowerShell runspace. Never execute unvalidated arguments.

    5. 5

      Return the result to the model

      Append a message with role “tool” containing the JSON result and resend the conversation. The model now answers, or chains the next tool. Forgetting this message is the classic bug: the model never saw the result and invents an outcome.

    6. 6

      Log every call

      Persist name, arguments, caller and result for each execution. When (not if) an argument turns out wrong, this log is the difference between a five-minute fix and an unexplainable incident.

    A tool_call the model emits
    { "name": "get_intune_device", "arguments": "{\"deviceName\": \"LAP-042\"}" }

    07Common mistakes

    • Executing model-supplied arguments without validation — an LLM can produce "deviceName": "LAP-042; Remove-Item" in a string; validate types, lengths and enums before anything runs.
    • Vague tool descriptions — selection quality is a direct function of description quality; the schema is prompt material, not documentation for humans.
    • Returning 10,000-token raw JSON to the model — trim to the fields the task needs; huge payloads waste tokens and drown the signal.
    • One powerful “run_command” tool instead of narrow named tools — narrow tools with least privilege are auditable and safe; a generic shell is neither.
    • Forgetting the “tool” role message — the model never sees the result and hallucinates an outcome.

    08Security considerations

    Treat every tool as a privilege escalation surface. Run tools under a least-privilege identity: a Graph app registration scoped to Device.Read-only today, ReadWrite only when a workflow truly needs it; a read-only SQL user, never the owner; PowerShell inside a constrained runspace with allow-listed cmdlets, never an open shell. Validate all arguments server-side (type, enum, length), rate-limit tool executions per user, and log name + arguments + result for audit. Remember indirect prompt injection too: content the model reads can instruct it to call a tool — topic 19 covers the defenses in depth.

    09Interview questions

    Q1What exactly does the model do in function calling?

    It only selects and fills: given tool schemas and the conversation, it emits a tool_call — a function name plus JSON arguments. Execution is entirely your code, and the result returns to the model as a “tool” message so it can compose the final answer. This separation is what makes the pattern auditable: nothing runs unless your validated backend runs it.

    Q2How do you make tool selection reliable?

    Three levers: precise, task-scoped schemas with concrete descriptions; few tools per assistant (3-10) so selection stays unambiguous; and strict parameter schemas with enums and descriptions that pin formats. Beyond the schema, log and replay failures — most selection errors trace back to overlapping or vague tools.

    Q3How would you expose PowerShell to an LLM safely?

    Not as an open shell. Wrap specific scripts as named tools (“get_log_tail”, “get_service_status”) executed in a constrained runspace with an allow-listed cmdlet set, a read-only service identity, timeouts and output size caps, with every invocation logged. The model chooses which tool to call; it never writes script text that gets executed verbatim.

    10Hands-on exercise

    Wrap two real functions as tools — get_error_rule(code) against your topic-13 vector store, and get_intune_device(name) against Graph’s read-only API. Give the model both schemas and the question “why does LAP-042 fail App X with 0x87D1041C?” — and require it to use both tools before answering.

    11Related CloudEngineerHub articles

    • Automating Intune with Microsoft Graph & PowerShell
    • PowerShell Error Handling Guide
    • Intune Device Compliance Policies

    12FAQ

    Is function calling the same as the model executing code?

    No — and the distinction is the whole security model. The model emits structured JSON describing a call; your backend validates and executes it with its own credentials and permissions. The model has no runtime, no shell and no network access of its own.

    Are parallel tool calls supported?

    Yes on modern APIs: the model can request multiple tool calls in one turn — e.g. get_device and get_error_rule together. Execute independent calls concurrently, then return all results as separate “tool” messages. Watch ordering when calls depend on each other’s outputs.

    How many tools can one assistant have?

    Technically dozens; practically 3-10 for reliable selection. With large tool sets, group by scenario or add a routing step (“triage tools” vs “remediation tools”) — and expect accuracy to fall as schemas crowd the prompt.

    Previous topic16 · AI Agents Explained — From Chatbots to Autonomous WorkflowsNext topic 18 · AI Memory, Context Windows & Conversation State