How I Test My Laravel AI Features Before They Reach Production
LLM outputs are non-deterministic, so AI features need their own testing layers. Here is my Laravel pipeline: Pest tests for the plumbing, golden datasets for behavior, and LLM-as-a-judge for quality.
Umar Farooq
System Architect & Full-Stack Engineer

Test LLM App Laravel: My Evaluation Pipeline Before Production
A prompt tweak that looked harmless changed my summarizer's answers, and no test caught it. The feature still returned 200 OK and the JSON still parsed. The text just quietly got worse. Traditional tests check that code runs, but AI features fail in meaning, not in syntax. This post is my playbook to test LLM app Laravel features before production. It has four plays, and each one catches a different failure.
Quick Answer: Testing LLM features needs four plays because no single test covers everything. Play 1: Pest tests with faked HTTP check your plumbing, retries, and parsing. Play 2: a golden dataset of real examples checks behavior across prompt changes. Play 3: an LLM-as-a-judge scores quality dimensions code cannot check. Play 4: CI gates run the cheap layers on every change, and production sampling watches for drift.
The Prompt Tweak That Broke the Summary
I had built an order-summary feature for a distribution client in Riyadh. It produced a short Arabic-friendly summary with totals for the sales team. The feature worked, the team liked it, and life was good.
Then I tweaked the prompt to sound friendlier. One sentence changed. The tests were green because they only checked the HTTP status and the JSON shape. Nothing in the suite read the actual words.
On long orders, the new wording dropped the VAT line. Nobody noticed for days, because the output still looked clean. A salesperson spotted the missing tax total while preparing a quote.
That was the day I stopped treating prompts as config. Prompts are code, and a prompt change deserves the same test coverage as a code change. Here are the four plays that came out of that incident.
Play 1: Test the Plumbing with Pest (Fast, Deterministic)
What to do. Pest is the expressive PHP testing framework from a Laravel core team member. It is my default for new Laravel work. Start with the plumbing, not the model. Write tests for retries, timeouts, response parsing, error handling, and provider outages. Use Http::fake() to intercept outgoing HTTP calls in tests. Your suite never spends money and never waits on a real API. Cover the unhappy paths first, because they fail the loudest in production. Run this suite on every commit.
<?php
use App\Services\AI\OrderSummarizer;
use Illuminate\Support\Facades\Http;
use function Pest\Laravel\postJson;
it('summarises an order and stores the result', function () {
// Fake the provider: deterministic, free, fast.
Http::fake(['api.openai.com/*' => Http::response([
'choices' => [['message' => ['content' =>
'{"summary":"...","total":1150}']]],
], 200)]);
$order = Order::factory()->create();
postJson('/api/orders/' . $order->id . '/summarise')
->assertOk()->assertJsonPath('data.total', 1150);
});
it('maps a provider outage to a 503', function () {
Http::fake(['api.openai.com/*' => Http::response(null, 500)]);
$order = Order::factory()->create();
postJson('/api/orders/' . $order->id . '/summarise')
->assertStatus(503);
});
Why it works. These tests run in milliseconds and cost nothing, so they can guard every commit. They catch crashes, broken JSON parsing, missing retries, and bad error mapping before any real traffic arrives. They will never catch real model weirdness, and that is fine. That is what the later plays are for. Skip this layer and your evals will be flaky, because you will be debugging network flakiness instead of model behavior.
Play 2: Build a Golden Dataset
What to do. A golden dataset is a fixed set of inputs paired with expected outputs. It is your regression suite for behavior. When you change a prompt or the provider ships a new model version, run the dataset. Then diff the results. Start small with 20 to 50 examples drawn from real failures, not happy paths. Grow toward 100 or more as the feature matures.
Store the set as JSON under tests/Fixtures/ai/. Each case carries four fields. The input is the prompt or document the feature receives. The expected_contains field lists strings that must appear in a good answer, such as the VAT line. The must_not_contain field lists strings that must never appear, such as another tenant's data. The notes field records why this case exists, which is usually a past incident.
Why it works. My VAT-line bug became example number one in my dataset, and it can never ship silently again. A golden dataset turns every production incident into permanent protection. Add every production failure to the dataset the week it happens, while the context is fresh. Skip this layer and prompt tweaks ship blind, because nothing remembers what broke last time. My guide to cutting LLM API costs in Laravel pairs well with this play. A golden dataset also proves your cheaper prompts still answer correctly.
Play 3: Add an LLM Judge
What to do. Some qualities cannot be asserted with code. Is the summary faithful? Is the tone right? Did it hallucinate a discount? An LLM-as-a-judge is a second model that scores outputs against a rubric. Calibrate it against human labels first, or you are grading with an untested grader. Use one metric per judge call. Combined rubrics produce unreliable scores, a finding repeated across evaluation guides including the Comet LLM-as-a-judge guide. Ask the judge to reason before scoring, since scores get more reliable that way. Judge calls cost money, so run them nightly, not per commit.
<?php
// One metric per judge call. The judge reasons first,
// then prints the score, which keeps scores stable.
$res = Http::post('https://api.openai.com/v1/chat/completions', [
'model' => config('ai.judge_model'),
'messages' => [[
'role' => 'user',
'content' => "Rate faithfulness 1-10. " .
"Reason first, then SCORE: <n>.\n" .
"Input: {$input}\nSummary: {$output}",
]],
])->json();
preg_match('/SCORE:\s*(\d+)/', $res['choices'][0]['message']['content'], $m);
$score = (int) ($m[1] ?? 0); // fail the build if below threshold
Why it works. A judge catches quality decay that no assertion can express, like a summary that is technically correct but misleading. Calibration keeps it honest: score a human-labeled sample first and measure agreement before you trust it. Re-check calibration when you change the judge model, because a new grader needs new proof. Skip this layer and quality arguments stay subjective, and subjective arguments lose to deadlines.
Play 4: Gate CI and Watch Production
What to do. Wire the cheap layers into CI. Run Pest on every commit. Run the golden dataset on prompt or model changes. Run the judge on a schedule, nightly works well. Fail the build when scores drop below your threshold, so a bad prompt cannot merge quietly.
Then watch production, because live traffic always differs from your dataset. Sample real outputs, score them with the judge, and track the trend over time. When scores drift, add new examples to the golden dataset and the cycle repeats. The ZycoSoft evaluation framework guide describes this offline-plus-online split well. For the broader picture, see my checklist on whether a vibe-coded app is production ready. It covers what else to verify before launch.
Why it works. CI gates turn evaluations from a chore into a wall: bad changes bounce before they reach users. Production sampling catches what no dataset can, which is drift from model updates and new user patterns. Skip this layer and you learn about decay from users, which is the most expensive monitoring system ever built. When you test LLM app Laravel features this way, every layer backs up the next.
What Each Play Catches When You Test LLM App Laravel Features
Play 1 catches crashes, bad JSON, and provider outages, and it does it in milliseconds for free. Play 2 catches regressions like my missing VAT line, across prompt and model changes. Play 3 catches quality decay that code cannot express, like unfaithful or mis-toned summaries. Play 4 catches drift from model updates and new user patterns, continuously.
Skip play 1 and your evals will be flaky. Skip play 2 and prompt tweaks ship blind. Skip play 3 and quality arguments stay subjective. Skip play 4 and you learn about decay from users. I learned each of these the expensive way, so you do not have to. For the RAG-specific side, my RAG vs fine-tuning guide covers when retrieval quality is the thing to measure. My Laravel AI SDK walkthrough shows where the model calls live in a Laravel stack.
Frequently Asked Questions
What is a golden dataset for LLM testing?
A golden dataset is a fixed set of inputs paired with expected outputs or quality labels, used as a benchmark. When you change a prompt or model, you rerun the dataset to check nothing got worse. Start with 20 to 50 examples drawn from real failures, not happy paths. Add every production failure the week it happens.
Can I trust an LLM to grade another LLM?
Partly, and only after calibration. Score a human-labeled sample with the judge first, then measure how often the judge agrees with humans. Keep rubrics narrow, ask for reasoning before the score, and re-check calibration when you change the judge model. A judge is a measuring tool, and measuring tools need calibration.
How many test cases do I need for LLM evaluation?
Fewer than you fear, but better chosen than you hope. Start with 20 to 50 real-failure cases. Growing toward 100 or more gives you a regression suite that detects meaningful changes. A hundred diverse, unambiguous cases beat a thousand synthetic happy paths every time.
Should I run LLM evals in CI on every commit?
Run the cheap layers on every commit: Pest tests and deterministic checks. Run the golden dataset when prompts or models change. Run the LLM judge on a schedule, because judge calls cost money and add minutes. Fail the build on a judge-score drop once your thresholds are calibrated.
What is the difference between LLM testing and LLM evaluation?
Testing means deterministic checks: does the code handle errors, parse responses, and retry correctly. Evaluation means judging output quality: is the answer faithful, complete, and well-toned. AI features need both. A feature can pass every unit test while producing confidently wrong text.
How do I test RAG features in Laravel?
Test retrieval and generation separately. For retrieval, assert that the right documents come back for known questions, using your vector store's actual index. For generation, check faithfulness: does the answer stay grounded in the retrieved chunks, or does it invent facts. My Laravel AI SDK walkthrough shows where retrieval fits in a Laravel stack.
Is Pest better than PHPUnit for testing Laravel AI features?
For this pipeline, Pest is my pick. It is the expressive PHP testing framework from a Laravel core team member. Its syntax keeps test files short and readable. Either framework can fake HTTP and assert behavior. Pick the one your team will actually read and maintain, then write the tests.
How do I stop a prompt change from breaking production?
Run your golden dataset before the change merges and fail the build if scores drop. Add the new behavior to the dataset the week it ships. Keep the judge running nightly so drift gets caught within a day. Prompts are code, so give them code-level gates.
Test LLM App Laravel Features Before Production: My Weekly Routine
To test LLM app Laravel features before production, build four plays. First, Pest tests with faked HTTP for the plumbing. Second, a golden dataset of real failures for behavior. Third, an LLM judge with narrow rubrics for quality. Fourth, CI gates plus production sampling to catch drift. My missing VAT line taught me that prompts are code and deserve code-level coverage.
Start with plays one and two this week. They are free and fast. Add the judge next week, once you have a dataset worth grading. This order matters. Cheap deterministic tests first, expensive model-based checks second.
If you want an evaluation pipeline for your Laravel AI feature, message me here.
One last tip. Keep a short changelog for your prompts. Every tweak gets a date and a reason. When a score drops, the log tells you exactly which change to suspect first.

Umar Farooq
Author & ConsultantSpecializes in Laravel, Next.js, and AI products. 5+ years enterprise experience with 80+ delivered platforms and full source code ownership.
Related Engineering Insights

PHP2Shell: Why Governments Took Their Own Websites Offline
When two flaws in PHP were disclosed on 21 October, governments did not wait to see what happened. They switched their own websites off. This is the full story of PHP2Shell, why around 70% of the web is exposed, and the one fix that actually works.

PHP2Shell: How to Check Your PHP Version and Fix It Today
Two critical flaws in PHP itself, rated 9.2 out of 10, let anyone run code on an unpatched server without a login. Updating WordPress does not fix this. Here is how to check your PHP version, patch it, restart it properly, and confirm you are safe.

The 10-Minute Database Check Every Vibe-Coded App Needs Before Launch
A timed 10-minute database security checklist for vibe-coded apps: find tables with Row Level Security off, lock them down with policies, and verify like an attacker, with exact SQL included.