AI-first development

Adding AI features to a Laravel app: a practical guide

Where AI features actually help in a Laravel application, how to build them with queues, structured output and cost controls, and the mistakes to avoid.

Key takeaways

  • Start with a narrow, repetitive task where a person checks the result, not a general chatbot.
  • Treat an AI model like any slow, occasionally failing third-party API, with queues, retries and logging.
  • Ask for structured output and validate it like user input.
  • Track cost per feature from day one, and keep personal data out of prompts unless you have checked the provider's terms.

Most businesses we speak to want "AI in the product", but are not sure what that should mean. The good news is that the most valuable AI features are usually the least glamorous. They take a slow, repetitive task that a person already does and make it quicker.

This guide covers where AI features earn their keep in a Laravel application, how to build them so they are reliable, and the mistakes we see most often.

Where AI features actually help

The best candidates share three traits: the task is repetitive, the input is mostly text or documents, and a person can easily check the result.

  • Summaries. A long customer history, support thread or set of notes condensed into a few lines for the person about to call the customer.
  • Classification. Tagging support tickets, routing enquiries, flagging risky content or categorising transactions.
  • Extraction. Pulling names, dates, amounts and line items out of uploaded documents, emails or PDFs.
  • Drafting. First drafts of replies, descriptions or reports that a person edits and approves.
  • Search. Finding records by meaning rather than exact words, using embeddings and vector search.

A general-purpose chatbot is rarely the right first project. It is hard to make reliable, hard to measure and easy for users to push in directions you did not plan for.

Treat the model like any other API

From your application's point of view, an AI model is a third-party API that is slow, costs money per call and sometimes fails or returns something unexpected. Laravel already has good tools for that kind of service.

Use queues. Model calls can take several seconds. Run them in a queued job so the user is not left waiting, and update the page when the result is ready.

SummariseCustomerHistory::dispatch($customer);

Retry sensibly. Use the job's retry and back-off settings to handle rate limits and temporary errors without manual work.

Log every call. Record the prompt version, model, token counts, cost and outcome. When a user reports a strange result, you will want to see exactly what happened.

Use a package rather than raw HTTP calls. Laravel 13 introduced a first-party AI SDK, and community packages such as Prism give a consistent interface across providers. Either makes it easier to switch models later.

Ask for structure, then validate it

Free text is hard to use in code. Ask the model to return JSON that matches a schema you define, such as a category, a confidence score and a short reason. Most providers now support structured output directly.

Then validate the response exactly as you would validate user input. Check the category is one you recognise and the numbers are in range. If validation fails, retry or fall back to a person.

Keep a person in the loop

For anything that affects customers, money or legal obligations, the AI suggests and a person decides. In practice that means:

  • drafts that must be approved before sending,
  • suggested categories that a person can change,
  • extracted data shown for review before it is saved.

This is not only about safety. It also gives you a steady stream of corrections, which show you where the feature works and where it needs better prompts or examples.

Control the cost

AI costs are easy to ignore in development and surprising in production. From the first day:

  • record the cost of every call against the feature and the customer account,
  • set limits per account, especially on free plans,
  • cache results where the same input is likely to come up again, and
  • use smaller, cheaper models for simple tasks such as classification.

Protect personal data

Before sending customer data to a model, check the provider's terms on data retention and training, and whether processing happens in a region that suits your obligations under UK GDPR. Send only the fields the task needs. For some tasks you can strip or replace names and contact details before the call and add them back afterwards.

Update your privacy notice to explain how AI processing is used.

Measure whether it works

Decide how you will judge the feature before you build it. Useful measures include how often people accept a suggestion without changes, how much time a task now takes and how many results are corrected. Keep a small set of real examples with known good answers, and run them whenever you change a prompt or a model.

Getting started

A good first AI feature can often be built and in front of users within a few weeks. If you would like help choosing the right one and building it properly, see our Laravel AI integration service, or book a free call to talk it through.

Keep reading

Security and patching

Laravel security checklist for 2026

A practical Laravel security checklist covering versions, authorisation, input handling, secrets, dependencies, headers, servers and monitoring.

· 3 min read

Talk to a senior Laravel engineer

Book a free 30-minute call. Tell us what you are building or what is worrying you, and we will tell you honestly what we would do, what it costs and how long it takes.