Truncated and refused replies
A real model does not always finish its answer: it can run out of tokens, or decline. To test how your app handles that, give a response rule a stopReason:
json
{
"responseRules": [
{ "match": "Summarise this", "file": "fixtures/cut-off.txt", "stopReason": "max_tokens" },
{ "match": "Write the exploit", "file": "fixtures/refused.txt", "stopReason": "refusal" }
]
}The reply text is still the fixture, exactly as written. LLMock does not shorten it, so write a fixture that stops part-way through a sentence (or part-way through a JSON object, to test your parser).
What each provider gets
stopReason | claude | openai (and custom templates) | gemini |
|---|---|---|---|
end (the default) | stop_reason: "end_turn" | finish_reason: "stop" | finishReason: "STOP" |
max_tokens | stop_reason: "max_tokens" | finish_reason: "length" | finishReason: "MAX_TOKENS" |
refusal | stop_reason: "refusal" | finish_reason: "content_filter" | finishReason: "SAFETY" |
Details
- It works with
fileandfiles, and with static and streamed replies. In aclaudestream the value is in themessage_deltaevent; in an OpenAI-style stream it is the last chunk'sfinish_reason. A streamedgeminireply is OpenAI-style, so it carries theopenaivalue. - A refused
claudereply also carries thestop_detailsobject the Anthropic API sends with a refusal:{ "type": "refusal", "category": null, "explanation": null }. - A rule without
stopReasonbehaves exactly as before. Any other value stops the server at startup. - A tool-call rule's reply ends with
tool_use.