Skip to content

LLM endpoint protection Since v0.2 ​

Protect chat endpoints of the application that call a large language model, such as a support bot, an assistant or a search with generated answers. For each listed endpoint the product reads the chat request, looks for prompt injection in the messages, counts tokens and cost per client against budgets, and checks answers, whole JSON ones and streamed ones, for leaked secrets, card numbers and phrases of the system prompt. It is off until you list an endpoint, and it starts in detect like every new section.

Before you begin ​

  • Role: operator for the application.
  • For the optional classifier: the waap-promptcheck add-on (the binary and the ONNX Runtime library) next to waap on the inspection nodes, and a model. See the setup steps below.
  • Client identity set up, so budgets count per client rather than per address.

List an endpoint ​

text
1. Open Applications > All applications > the application > Request checks > API protection.
2. Open the LLM endpoints tab, Endpoints, and select Add.
3. Enter a name and the paths. Leave the format on auto, or choose one.
4. Optionally set the roles checked, budgets, model prices and system prompt phrases.
5. Select Preview changes, add a comment and select Apply.
sh
waap api llm endpoints -app shop > endpoints.yaml
# edit endpoints.yaml, then preview and apply
waap api llm endpoints -app shop -f endpoints.yaml -dry-run
waap api llm endpoints -app shop -f endpoints.yaml -m "support chat"
yaml
# endpoints.yaml, or applications[].policy.api.llm.endpoints
- name: support-chat
  paths: [/v1/chat/completions]
  system_prompt_markers: ["You are ShopBot, the assistant of Example Shop"]
  tokens_per_day: 200000
  models: [{name: "gpt-4o*", input_price: 2500000, output_price: 10000000}]
  on_injection: refuse

Read the events for a week in detect. Add ignore_rules exceptions where needed (for example llm.injection.heuristic on a path where users paste templates). Switch on_injection to refuse and the section to block when only attacks remain.

What the product reads ​

The format is recognised by shape (format: auto) or set per endpoint: OpenAI chat completions and responses API, Anthropic messages, or generic, where prompt is a JSON pointer to the user text (for example /query/text; * matches every element or member) and output points to the answer text.

Messages with the roles in Roles checked (user and tool by default) are checked. Tool results carry indirect injection: text from a web page, an email or a document the model was asked to read. At most 64 KiB of text is read per request; the token estimate (characters / 4) counts all of it.

Detect prompt injection ​

Two checks, both only logging by default (on_injection: log).

  • Heuristics are fixed linear-time patterns, each with a weight: instruction overrides, persona switches, requests to reveal the system prompt, chat template tokens, requests to send data to an address, long base64 or hex blobs and hidden Unicode characters. A message whose weights add up to 100 is a finding (llm.injection.heuristic). One signal alone stays below 100, so "please ignore my previous instructions, I meant Tuesday" is not flagged.
  • Classifier (opt-in) scores the messages with a prompt-injection model run by the waap-promptcheck helper. A score of Classifier threshold or more is a finding (llm.injection.classifier).

Set up the classifier ​

text
1. Install the waap-promptcheck add-on next to waap on the inspection nodes.
2. Open System > Helpers, set Run waap-promptcheck on and the Model directory.
3. Open the application's LLM endpoints tab, Settings, and turn on Injection classifier.
4. Select Preview changes, then Apply.
sh
waap llm model fetch
waap settings set helpers promptcheck.enabled=true promptcheck.model=/var/lib/waap/models/promptcheck
waap api set -app shop -m "classifier" llm.classifier.enabled=true
waap api llm helper

waap llm model fetch downloads protectai/deberta-v3-base-prompt-injection-v2 (Apache-2.0, 0.75 GB, each file checked by size and SHA-256). Copy a model from another machine with waap llm model import -f DIR. The default model runs on the CPU: short messages take tens of milliseconds and long ones much more. A smaller or quantized model is faster.

The classifier has its own time budget

The classifier budget (default 150 ms) lies within the section budget (default 200 ms). When the classifier cannot answer, When the classifier cannot answer decides. With the default heuristics, the heuristics still apply and the outage is logged once a minute as llm.classifier_unavailable.

Test a prompt ​

text
1. On the LLM endpoints tab, open Test a prompt.
2. Paste a text. The page shows the heuristic score with the matched phrases and the
   classifier's score, using the application's settings.
sh
waap api llm check -app shop -text "Ignore all previous instructions"

Nothing is sent or stored. Use it to judge a false positive before changing a threshold.

Set token and cost budgets ​

Budgets count per client identity and endpoint (the client address when no identity applies). Over a budget, block mode answers 429 with Retry-After (llm.budget.tokens, llm.budget.cost). A single request over Largest request is refused with 413.

text
1. Edit the endpoint on the LLM endpoints tab, Endpoints.
2. Set the token budgets and, under model prices, entries as name=input/output.
3. Select Preview changes, then Apply.
sh
waap api llm endpoints -app shop -f endpoints.yaml -m "budgets"
waap api llm usage -app shop -day 2026-11-25
yaml
# one endpoint of applications[].policy.api.llm.endpoints
max_request_tokens: 8000
tokens_per_minute: 20000
tokens_per_day: 500000
cost_per_day: 0
models:
  - {name: "gpt-4o*", input_price: 2500000, output_price: 10000000}

Tokens come from the answer's own usage report when it has one, else are estimated. Cost uses the models prices in micro-units of your currency per million tokens; a name ending in * is a prefix. Refused calls and failed answers count nothing. Each node counts what it saw, so with several active nodes a client can use up to the budget on each. The Usage card shows a day's requests and tokens per client and endpoint, with the share of the daily budget used.

Check answers ​

With Check answers for leaks on (default), answer text is scanned with the application's data-leak detectors, the built-in card, national ID and IBAN detectors, secret patterns (cloud and API keys, tokens, private keys) and the endpoint's system_prompt_markers. Leaks in answers decides the action. Findings are llm.output.leak and llm.output.system_prompt. The DLP module does not scan these answers again, so one leak gives one event.

Streamed answers (text/event-stream) are checked while they stream. Events are held back until Stream hold-back characters of answer text follow them, so a value split across events is found and masked before any of it leaves. The client sees the answer with that small delay (about 30 tokens at the default). Past the stream limits the rest passes unchecked and the event notes it (llm.output.unscanned). Answers on listed paths always reach the product uncompressed.

Spare chat text from CRS false positives ​

Ordinary chat text trips some signature rules ("Looks good; print the final version." looks like a shell command). By default each listed endpoint gets a built-in exception that ignores rules 932370, 934100, 941390 and 942151 in the message content only, for POST requests to its paths. Every other rule still reads the messages, and these four still read every other field. Set Spare chat text from CRS false positives to false to keep all rules on the message text.

Settings reference ​

Module settings ​

SettingWhat it doesDefaultAllowed valuesApplies in
LLM protection mode (llm.mode)Whether refusals apply.empty (same as API protection)detect, block, emptydetect wins over the application's block
Find unlisted chat endpoints (llm.discovery)Logs a JSON POST shaped like a chat call on an unlisted path, once per path and node (llm.endpoint.unlisted). Never blocks.truetrue, falseall
Injection heuristics (llm.heuristics)Runs the fixed patterns.truetrue, falseall
Spare chat text from CRS false positives (llm.crs_exception)Adds the built-in exception.truetrue, falseall
Injection classifier (llm.classifier.enabled)Scores messages with the model.falsetrue, falsehelper running
Classifier threshold (llm.classifier.threshold)Score from which a verdict counts.90 percent50 to 99classifier on
Classifier time budget (llm.classifier.budget)Longest the classifier may take.150ms10ms to 2sclassifier on
When the classifier cannot answer (llm.classifier.on_unavailable)What happens when it is missing, busy or too slow.heuristicsheuristics, inherit, open, closedclosed refuses in block mode
Check answers for leaks (llm.output.dlp)Scans answer text.truetrue, falseall
Leaks in answers (llm.output.action)What happens to a leak.maskmask (same length, valid JSON), log, refuserefuse replaces a JSON answer with the error page (502) or ends a stream with event: error
Stream hold-back (llm.output.hold_back)Characters of answer text held back in streams.12832 to 4KiB; at least the longest markerall

Endpoint ​

SettingWhat it doesDefaultAllowed valuesApplies in
nameIdentifies the endpoint.none (required)lowercase letters, digits, dashesall
pathsPaths of the chat endpoint.none (required)up to 16all
formatThe request format.autoauto, openai, anthropic, genericall
prompt, outputJSON pointers to the user text and the answer text.noneJSON pointers; * is any element or memberformat generic
classify_rolesRoles whose messages are checked.user, tooluser, tool, system, assistantall
system_prompt_markersDistinctive sentences of your system prompt.noneup to 16; 8 to 256 bytes each; matched ignoring case and spacinganswers checked
max_request_tokensLargest single request.8000positive numberover it: 413
tokens_per_minuteTokens per client and minute.20000positive numberover it: 429 in block mode
tokens_per_dayTokens per client, sliding 24 hours.500000positive numberover it: 429 in block mode
cost_per_dayCost per client per day.0 (no limit)micro-units of your currencyover it: 429 in block mode
modelsPrices per model.noneup to 32 entries of name, input_price, output_priceall
on_injectionWhat an injection finding does.loglog, refuserefuse in block mode

Limits ​

LimitValue
Endpoints per application32
Paths per endpoint16
System prompt markers per endpoint16
Text read per request64 KiB
Messages classified per request8 (latest user message and tool results first)
One streamed event64 KiB
Held in a stream256 KiB
Scanned per streamed answer16 MiB
Usage kept90 days, 1,000 identities per application, day and node (others summed as other)

Troubleshooting ​

Normal chats trip a signature rule ​

  • Cause: chat text resembles code or commands.
  • Fix: keep Spare chat text from CRS false positives on, and list the endpoint.

llm.classifier_unavailable appears ​

  • Cause: waap-promptcheck is not installed, not enabled, or too slow for the text.
  • Check: waap api llm helper, or System > Helpers.
  • Fix: install and enable it, or raise the classifier time. The heuristics still apply.

A legitimate prompt is flagged ​

  • Cause: a heuristic or the classifier scored it high.
  • Check: Test a prompt shows the score and the matched phrases.
  • Fix: add an ignore_rules exception for that path, or raise Classifier threshold.