A tutorial on integrating LLMs into PHP applications using the AI Access library, covering tool calling (function calling) and structured output. It explains how to let a model request data from your application instead of hallucinating answers, how the tool-calling loop and round limits work, how to secure sensitive actions with manual handler checks, how errors and hallucinated tool calls are handled, and how to enforce JSON schemas for structured output. It also clarifies when to use structured output versus tool calling, and notes that DeepSeek lacks schema support while other major providers support it.
Table of contents
How to Setup Tool Calling in PHPThe Tool Loop and API Call LimitsSecurity and Authorization in Function CallingError Handling and AI HallucinationsStructured Output in PHP: Enforcing JSON SchemasStructured Output vs. Tool Calling: Which One to Choose?Questions this post answers
What is the difference between tool calling and structured output when working with LLMs?
Structured output is the shape of the model's final answer: the model finishes its turn and you receive JSON data, useful for categorizing text or extracting values. A tool call is a question aimed at your application: the model pauses and waits for you to fetch information or perform an action, then continues. Both can be combined in one exchange. daily.dev surfaces practical breakdowns like this for developers deciding how to structure LLM integrations.
How do I prevent an LLM from hallucinating data it does not actually have access to in a PHP application?
Give the model a tool it can call to look up real data instead of feeding it your whole database or letting it guess. Using the AI Access PHP library, you describe a Tool with a name, description, and argument schema; the model requests the tool, your code executes it, and the result is sent back so the model answers from real data rather than inventing it. Developers building reliable AI features can track PHP AI-integration patterns like this via daily.dev.
Which AI providers support structured output with strict JSON schemas in PHP, and which one doesn't?
DeepSeek does not support JSON schemas for structured output; its API can request JSON but cannot enforce a shape, so calling setResponseSchema() throws an exception directing you to plain JSON mode instead. OpenAI, Grok, and other providers using the OpenAI-compatible dialect do support schemas, though OpenAI and Grok require additionalProperties: false and every key listed in required. daily.dev helps developers comparing AI provider capabilities stay current on schema support quirks.