Guardrail that validates content length constraints.

Validates both character count and word count to ensure content meets size requirements. Useful for preventing:

  • Excessively long inputs that waste tokens
  • Empty or trivial inputs
  • DOS attacks via extremely long content
const lengthGuardrail = new ContentLengthGuardrail({
minLength: 10,
maxLength: 5000,
minWords: 2,
maxWords: 1000,
severity: GuardrailSeverity.WARNING,
});

const result = await lengthGuardrail.evaluate({
content: 'A'.repeat(10000),
contentType: 'input',
});

console.log(result.passed); // false (exceeds maxLength)

Implements

  • Guardrail

Constructors

Methods

Properties

Constructors

Methods

  • Evaluate content against this guardrail

    Parameters

    • context: GuardrailContext

      Evaluation context

    Returns Promise<GuardrailResult>

    Result of the evaluation

Properties

name: "content-length" = 'content-length'

Unique name of the guardrail

description: "Validates content length constraints" = 'Validates content length constraints'

Human-readable description

enabled: boolean

Whether this guardrail is enabled