<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli" -->

---
title: Tool Calling & Structured Output in PHP: AI Integration...
description: A tutorial on integrating LLMs into PHP applications using the AI Access library, covering tool calling (function calling) and structured output. It explains...
canonical: https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Tool Calling & Structured Output in PHP: AI Integration Guide – Nette Blog | daily.dev
og:description: A tutorial on integrating LLMs into PHP applications using the AI Access library, covering tool calling (function calling) and structured output. It explains...
og:url: https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli
og:image: https://api.daily.dev/og/posts/Dv1rTKbLI.png
og:image:alt: Tool Calling & Structured Output in PHP: AI Integration Guide – Nette Blog
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Tool Calling & Structured Output in PHP: AI Integration Guide – Nette Blog

**[Nette](https://daily.dev/sources/nette)** · 10 min read · 3 upvotes · 0 comments

## Summary

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.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.nette.org/en/php-tool-calling-structured-output>

## Questions this post answers

### How do I implement tool calling (function calling) for an LLM in PHP?

Use the AI Access PHP library, which reached version 1.0: describe a tool with a Tool object containing a name, description, argument schema, and handler function, then call sendMessage(). The library automatically calls your handler when the model requests a tool, sends the result back, and waits for the model's answer, chaining multiple tool calls in a loop capped at eight rounds by default.

_daily.dev surfaces practical guides like this for developers wiring LLM tool calling into PHP apps._

### How do I get an LLM to return valid JSON instead of text with markdown around it?

Enforce a strict JSON schema using structured output rather than just asking for JSON in a prompt, since providers enforce the shape rather than relying on the model's compliance. Calling getJson() returns already-decoded data with no markdown stripping needed. Note that DeepSeek lacks schema support entirely; setResponseSchema() throws an exception there, forcing a fallback to plain JSON mode.

_Developers hardening LLM outputs against malformed JSON can find this kind of provider-specific detail on daily.dev._

### What's the difference between tool calling and structured output in LLM applications?

Structured output is the shape of the model's finished answer, useful for tasks like categorizing an email or extracting values into fields. A tool call is a question the model asks of the application, pausing until the app supplies information or performs an action, useful when the model needs data or actions the app controls. The two can be combined in a single exchange.

_Teams deciding between tool calling and structured output for an AI feature can track guidance like this on daily.dev._

## Similar posts on daily.dev

- [Structured Outputs in LLM Applications: A Complete C\# Developer Guide](https://daily.dev/posts/structured-outputs-in-llm-applications-a-complete-c-developer-guide-yys1kk1ad) · C\# Corner · 3 upvotes · 0 comments
- [Ship AI with Laravel: Smart Ticket Triage with Structured Output](https://daily.dev/posts/ship-ai-with-laravel-smart-ticket-triage-with-structured-output-ex8biah25) · Laravel News · 1 upvotes · 0 comments
- [Stop Building Dumb AI Wrappers: Getting Real with LLM Function Calling](https://daily.dev/posts/stop-building-dumb-ai-wrappers-getting-real-with-llm-function-calling-15jnyvyrb) · SitePoint · 0 upvotes · 0 comments
- [Tool Calling, Explained: How AI Agents Decide What to Do Next](https://daily.dev/posts/tool-calling-explained-how-ai-agents-decide-what-to-do-next-ug95msj09) · Towards Data Science · 1 upvotes · 0 comments

---

Tags: [#llm](https://daily.dev/tags/llm), [#php](https://daily.dev/tags/php)

[View this post on daily.dev](https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Tool Calling & Structured Output in PHP: AI Integration Guide – Nette Blog","url":"https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli"},"datePublished":"2026-08-17T16:01:45.195Z","dateModified":"2026-09-14T09:01:52.079Z","description":"A tutorial on integrating LLMs into PHP applications using the AI Access library, covering tool calling (function calling) and structured output. It explains...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8bf45c5dc6d0f7d741ba841a0aac6978?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8bf45c5dc6d0f7d741ba841a0aac6978?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Nette","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Nette","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/54476ee5012b4cdaa4811d869af060ed","url":"https://daily.dev/sources/nette"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"llm,php","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Nette","item":"https://daily.dev/sources/nette"},{"@type":"ListItem","position":3,"name":"Tool Calling & Structured Output in PHP: AI Integration Guide – Nette Blog"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/tool-calling-structured-output-in-php-ai-integration-guide-nette-blog-dv1rtkbli#faq","mainEntity":[{"@type":"Question","name":"How do I implement tool calling (function calling) for an LLM in PHP?","acceptedAnswer":{"@type":"Answer","text":"Use the AI Access PHP library, which reached version 1.0: describe a tool with a Tool object containing a name, description, argument schema, and handler function, then call sendMessage(). The library automatically calls your handler when the model requests a tool, sends the result back, and waits for the model's answer, chaining multiple tool calls in a loop capped at eight rounds by default. daily.dev surfaces practical guides like this for developers wiring LLM tool calling into PHP apps."}},{"@type":"Question","name":"How do I get an LLM to return valid JSON instead of text with markdown around it?","acceptedAnswer":{"@type":"Answer","text":"Enforce a strict JSON schema using structured output rather than just asking for JSON in a prompt, since providers enforce the shape rather than relying on the model's compliance. Calling getJson() returns already-decoded data with no markdown stripping needed. Note that DeepSeek lacks schema support entirely; setResponseSchema() throws an exception there, forcing a fallback to plain JSON mode. Developers hardening LLM outputs against malformed JSON can find this kind of provider-specific detail on daily.dev."}},{"@type":"Question","name":"What's the difference between tool calling and structured output in LLM applications?","acceptedAnswer":{"@type":"Answer","text":"Structured output is the shape of the model's finished answer, useful for tasks like categorizing an email or extracting values into fields. A tool call is a question the model asks of the application, pausing until the app supplies information or performs an action, useful when the model needs data or actions the app controls. The two can be combined in a single exchange. Teams deciding between tool calling and structured output for an AI feature can track guidance like this on daily.dev."}}]}
```

