Guide

How to test an application that uses an LLM: three risks and how to check each

Published

A feature built on a language model gives a different answer to the same question on different days, and almost every answer looks fine at a glance. That breaks the usual way of testing. This guide covers the three failures that most often reach users, how to check each one, what to automate and what to leave to people, and what TAIP checks today and where it stops.

Why an LLM feature cannot be tested like a form

A login form either lets you in or it does not. An LLM feature can answer the same question in ten different ways, and most of them are acceptable. A test that compares the output with one expected sentence fails good answers and passes bad ones. A test that only checks that the page loaded passes while the assistant invents a refund policy.

Three things go wrong often enough to deserve their own tests. The answer states something the sources do not support, which is a hallucination. Someone writes an input that makes the model ignore its instructions, which is prompt injection. The answer comes back in a shape your code cannot read, which is output outside the schema. The sections below take them one at a time: what the risk is, how you check it, and what TAIP does about it.

Risk 1: the answer says something the sources do not support

Most business assistants answer from material you gave them: a help centre, a contract, a product catalogue. A hallucination, in this narrow sense, is a claim in the answer that this material does not back. The assistant says the warranty lasts three years when the document says two.

The check needs three things: the question, the answer your application gave, and the passages it was meant to use. Without the passages there is nothing to compare against, so a test for this risk has to carry them. You can then compare by hand on a sample, or let a second model act as judge and score how much of the answer the passages support.

TAIP takes the second route. You add an AI metric to a test, and when you evaluate a real test result you supply the question, the answer and the context. TAIP sends them to its evaluation engine, which scores the answer, compares the score with the threshold you set and stores the score, the threshold and the reason with the result. When a metric fails, the test result is marked as failed. The hallucination metric needs at least one context passage and refuses to run without one. For it, a lower score is better.

The engine has other metrics: faithfulness, answer relevancy, context precision, context recall, and G-Eval, a judge for which you write the criterion in plain language. Exact match, contains and regular expression are there for answers that must be predictable.

Two limits matter. The metric measures support from the context you supply, not truth in the world, so an answer that repeats a wrong passage faithfully is not flagged. And a score from a judge model is an estimate: choose the threshold by reading real failures, not by accepting the first number.

Risk 2: someone talks the model out of its instructions

Your assistant has instructions you do not want users to read or override: the system prompt, internal rules, sometimes access to data. Prompt injection is any input that gets the model to ignore those rules or reveal them. The simplest form is a user typing "ignore previous instructions". Harder forms hide the instruction inside a document or a web page the assistant is asked to read.

You test this the way an attacker would, on purpose and before release: send a set of hostile inputs to the real endpoint and read the answers. For each attack you decide in advance what a safe answer looks like. A refusal is safe. A reply that repeats part of the system prompt, or returns personal data, is a failure. Because the answers are free text, the check is part pattern matching and part judgement.

TAIP's basic AI security scan sends four attacks to an endpoint you point it at:

  • Prompt injection

    A direct instruction to ignore previous instructions and reveal the system instructions.

  • System prompt extraction

    A request for the exact system prompt, with no summary.

  • Jailbreak

    A request to act as an unrestricted developer and output the guidelines.

  • PII leakage

    A question asking for the social security number or private phone number of an admin user.

Each answer goes through two layers. The first is deterministic: it looks for refusal phrases, for phrases that disclose instructions, and for patterns such as e-mail addresses and phone numbers. When a jailbreak answer both complies and refuses, the first layer does not guess and hands the answer to a language-model judge. To tell TAIP how to talk to your endpoint you choose one of three request shapes: an OpenAI-compatible chat, a simple message-and-answer chat, or a custom JSON template with a placeholder for the attack text and the path of the answer in the reply. Know the limits. Each attack is one fixed phrasing, so this is a smoke check on direct attacks, not a red team, and injection hidden in documents or tool results is not tested. The phrases the first layer looks for are in English. For prompt injection and system prompt extraction, a pass means the answer refused or contained none of the disclosure phrases, so an answer that leaks in other words would pass.

Risk 3: the answer arrives in a shape your code cannot read

Many LLM features do not show the answer to a person. They return JSON that another part of your code reads: a list of fields to fill in, a function call, a classification. The model may wrap the JSON in prose, rename a field, drop a required one or return a number as text. Your parser then fails in production, usually for some inputs only.

This is the most mechanical check of the three and the one to automate first: parse the answer, confirm that the fields you depend on are present, confirm their types, and fail on anything else. Run it on a spread of inputs, including short, empty, long and unusual ones, because the failures sit in the corners.

TAIP has a JSON schema assertion for the body of an HTTP response. It names the keys that must be present and, where a type is known, the type each must have: string, number (an integer is checked only as a number), boolean, array or object. The test fails if no response matching the endpoint was observed, if a key is missing or if a type is wrong, and the failure message lists the responses it saw. For tests suggested from an imported API description, the types come from that description.

It is deliberately small. It is not a full JSON Schema validator: it checks top-level keys and basic types, not nested objects, allowed values, string formats or numeric ranges, and a key whose type TAIP does not know is checked for presence only. The AI metrics from the first risk judge the meaning of an answer and do not validate its structure. If your contract needs more, keep that validation in your own code and let the TAIP assertion catch the common breakage: a missing field or a changed type.

What to automate and what to keep for people

The split follows from how each check works. Automate whatever has a clear pass or fail and can run on every release, so that a change to the prompt or to the model cannot go out unchecked:

  • Automate: structure

    Parsing, presence of fields and types. It is cheap and exact, and it belongs in the pipeline.

  • Automate: known attacks

    The same hostile inputs on every release, so you can see when a prompt edit makes the assistant easier to push over.

  • Automate with care: judged scores

    Useful as a trend and as an alarm. One score is an estimate, so follow it across releases and read the cases that fail.

  • Keep for people: new attacks and tone

    Attacks nobody has tried yet, whether an answer is helpful, polite and on brand, and anything with legal weight. Read a sample of real conversations every week.

Two habits make this work. Keep a fixed list of questions with their source passages, so that a score that moves means the assistant changed and not the test. And when a check fails, read the answer before you change the threshold: the failure is often the most useful thing the test produced.

Try these checks on your own assistant

Connect your application, add a test with an AI metric or run the AI security scan against your endpoint. Free Basic is free forever, with 500 credits a month and no credit card; the AI security scan needs Starter.