🎉 ai-infra v1.0 is here — Production-ready AI/LLM infrastructure
What's new
nfrax logonfrax

Infrastructure that just works. Ship products, not boilerplate.

Frameworks

  • svc-infra
  • ai-infra
  • fin-infra
  • robo-infra

Resources

  • Getting Started
  • What's New
  • Contributing

Community

  • GitHub

© 2026 nfrax. All rights reserved.

nfrax logonfrax
Start HereWhat's New
GitHub
ai-infra / API Reference

LengthInRange

from ai_infra.eval import LengthInRange
View source
ai_infra.eval
Extends:Evaluator[str, str]

Check if output length is within a specified range. Useful for ensuring responses are not too short or too long.

Args

min_length: Minimum allowed length. Default: 0. max_length: Maximum allowed length. Default: None (no limit). count_words: If True, count words instead of characters. Default: False.

Example

>>> from ai_infra.eval.evaluators import LengthInRange >>> from pydantic_evals import Case, Dataset >>> >>> dataset = Dataset( ... cases=[Case(inputs="Summarize this", expected_output=None)], ... evaluators=[LengthInRange(min_length=10, max_length=500)], ... )

Returns

EvaluationReason with pass/fail and length info

Constructor
LengthInRange(min_length: int = 0, max_length: int | None = None, count_words: bool = False) -> None
ParameterTypeDefaultDescription
min_lengthint0—
max_lengthint|NoneNone—
count_wordsboolFalse—

Methods

On This Page

Constructorevaluate