Skip to content

LengthGuard

LengthGuard enforces input length limits to prevent resource exhaustion and token limit attacks.

Overview

Property Value
Latency <1μs
Memory 0.5 KB
Async No
ML Required No

Usage

Rust

use oxide_guard::{Guard, LengthGuard};

let guard = LengthGuard::new("length")
    .with_max_chars(10000)
    .with_max_tokens(4000)
    .with_min_chars(1);

let result = guard.check(user_input);

Python

from oxideshield import length_guard

guard = length_guard(max_chars=10000, max_tokens=4000)
result = guard.check(user_input)

Configuration

Parameter Type Default Description
max_chars usize 100000 Maximum characters
max_tokens usize None Maximum tokens (tiktoken)
min_chars usize 0 Minimum characters
max_words usize None Maximum words
guards:
  length:
    enabled: true
    max_chars: 10000
    max_tokens: 4000