Test with a deliberately long input
Your test prompts are short. Your users' prompts are not. That gap is where truncation, drift and surprise bills hide. A test that is long on purpose finds them before users do.
What to test
- Does the rule survive? Put a clear, checkable rule at the start, pad the middle, ask a question at the end, and check the answer follows the rule.
- Does the fact survive? Put a fact early ("the order ID is 4471") and ask for it at the end.
- What happens at the limit? Send something just over your token budget. Your code should refuse or trim cleanly, not crash or send it anyway.
- Does the reply finish? Check the finish or stop reason on long answers. A length stop means your output cap was hit.
A small test script
This builds the long prompt and checks the reply. Send the prompt with your own client and pass the reply to passed(). The demo just checks two fake replies.
# Plant a rule at the start, pad the middle, ask at the end. Check the rule held.
def build_long_prompt(filler_paragraphs=200):
rule = "RULE: always end your answer with the word DONE."
filler = "\n".join(f"Note {i}: nothing important here." for i in range(filler_paragraphs))
question = "Question: what is 2 + 2?"
return f"{rule}\n\n{filler}\n\n{question}"
def passed(reply):
return reply.strip().endswith("DONE")
if __name__ == "__main__":
p = build_long_prompt()
print("prompt chars:", len(p))
print("pass?", passed("4. DONE"), passed("The answer is 4."))
Run each case many times, not once. Model output varies, so a rule that holds 9 times out of 10 will still fail in production. Track the pass rate.
Make the padding realistic
Filler like "nothing important here" is easy for a model to skip. For a harder test, pad with text that looks like your real data: old support tickets, logs, product pages. That is closer to what users send.
Move the rule and the fact around too: start, middle, end. If results drop when the fact is in the middle, you have learned something about your model and your prompt layout. Fix it with Put the important instruction last.
Watch the cost
Long tests use a lot of tokens. Keep a small set, run it before releases and on prompt changes, and use a cheaper model for early runs if the behavior you test does not depend on the model. Log token counts for each run so you know what the suite costs.
Add it to CI
- Store the long fixtures in your repo.
- Fail the build if the pass rate drops below a threshold you choose.
- Re-run when you change model, prompt or trimming code.
Checklist
- One rule test, one fact test, one over-limit test.
- Realistic padding.
- Many runs per case, track pass rate.
- Check finish reasons.
- Run on every prompt or model change.
Related: Truncation and lost instructions.