Skip to Content
LoremLLM

Matching

Every condition a scenario can match on, and how they combine.

A when is an object of conditions. All conditions in one when must pass. To match any of several, use anyOf.

when: {
  prompt: /refund/i,
  tools: ["lookupOrder"],
  turn: 1,
}

Conditions

ConditionMatches when
promptThe last user message contains a string, or matches a RegExp
systemThe system prompt contains a string, or matches a RegExp
semanticThe last user message is close in meaning to a reference text
turnThe conversation is on this turn number (1 is the first user message)
modelThe request asks for this model name, or matches a RegExp
headerEvery listed request header has the given value
toolsThe request offers every listed tool
toolResultThe last message is the result of this tool ({ name, output?, isError? } or a name)
schemaThe request asks for structured output (optionally with this schema name)
endpointThe request came in on this API: openai-chat, openai-responses, anthropic-messages, ai-sdk-ui, mcp, eve
anyOfAny of the nested when objects match
notThe nested when does not match

Text matching

A string matches if the text contains it, ignoring case. A RegExp is tested as written. Named groups land on match.groups, the same as RegExp.exec, and function replies receive them.

{
  when: { prompt: /weather in (?<city>[a-z ]+)/i },
  reply: ({ match }) => toolCall("getWeather", { city: match.groups.city }),
}

Semantic matching

semantic embeds the last user message and compares it with your reference text. It matches when cosine similarity is at or above threshold (default 0.8).

when: { semantic: { text: "How do I cancel my subscription?", threshold: 0.75 } }

Semantic matching is the only condition that is not exact. Two different phrasings of the same question will both match, which is useful for demos and UI prototypes. Use exact conditions in tests.

Headers

Header conditions let a test pick a scenario without changing the prompt:

when: { header: { "x-test-case": "rate-limit" } }

To force a scenario by name, send the built-in loremllm-scenario header instead. It skips matching entirely and picks the scenario whose name equals its value.


Every SDK lets you set default or per-request headers, so you can switch scenarios from a test without touching app code.

## Debugging a match

Every response carries `loremllm-scenario` with the matched scenario's name or index. The [inspector](/docs/platform/request-inspector) shows each condition that passed or failed for every scenario above the match.

On this page