Guardrail that validates content length constraints.
Validates both character count and word count to ensure content meets size requirements. Useful for preventing:
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) Copy
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)
Evaluate content against this guardrail
Evaluation context
Result of the evaluation
Readonly
Unique name of the guardrail
Human-readable description
Whether this guardrail is enabled
Guardrail that validates content length constraints.
Validates both character count and word count to ensure content meets size requirements. Useful for preventing:
Example