← Back to your requirements

How to meet it OWASP AISVS v1.01

Input Validation · Prompt Injection Defenses

Reject input that is too long

AISVS 2.1.4 Level 1

Verify that input length controls prevent content from exceeding the context window. The controls must reject inputs that exceed token limits rather than truncating them.

OWASP AISVS v1.01, requirement 2.1.4

In plain English

Set a limit on how much text each input can contain, and refuse anything over it. Do not quietly cut it down: trimming can push your own instructions or safety rules out of the model's context and leave the attacker's text in charge.

What good looks like

  • Limits are counted in tokens with the model's own tokenizer.
  • There are limits for each source (the user's message, each document, the whole prompt), with room left for your instructions and the reply.
  • Inputs over the limit are rejected with a clear error and logged.
  • When long conversations are shortened, a deliberate rule decides what goes, and your instructions are always kept.

How teams usually do it

  • Count tokens with the provider's tokenizer library (for example tiktoken for OpenAI models) in the gateway or wherever the prompt is assembled.
  • Add a request size limit at the API gateway as an outer cap.
  • Split and summarise long documents in a separate step, so no single prompt has to hold everything.

Evidence an auditor would accept

  • The configured limits for each input source.
  • Tests showing an over-limit input is rejected whole.
  • The prompt assembly code, showing where your instructions sit and that they are never trimmed.

Common mistakes

  • Limiting characters. The same number of characters can be many more tokens in some languages, or in text crafted to tokenise badly.
  • Assuming the provider will return an error. Some frameworks and conversation-memory helpers trim history automatically, so check what yours does.
  • Applying the limit to what the user types and forgetting retrieved documents and tool output.

Not sure which requirements apply to your system? Take the assessment.

Requirement text from the OWASP AI Security Verification Standard, licensed under CC BY-SA 4.0. This guidance is shared under the same licence.