Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Guardrails ai Guardrails Guard Streaming Configuration

From Leeroopedia
Knowledge Sources
Domains Streaming, Validation
Last Updated 2026-02-14 00:00 GMT

Overview

A configuration principle for preparing Guards with streaming-aware validators that define custom chunk boundary detection strategies.

Description

Guard Streaming Configuration addresses the challenge of validating LLM output that arrives incrementally as a stream of small text chunks. The same Guard.use() method is used for attaching validators, but for streaming scenarios, validators should implement a _chunking_function that defines how accumulated text is split into validation-ready segments.

The default chunking strategy uses sentence boundary detection, but validators can override this to validate at word, paragraph, or custom boundaries. This configuration step uses the same Guard.use() API but with awareness that validators will operate in streaming mode.

Usage

Apply this when setting up a Guard that will be called with stream=True. Ensure validators either support the default sentence-based chunking or implement custom _chunking_function methods appropriate for their validation logic.

Theoretical Basis

Streaming validation requires a buffering strategy:

  1. Chunk Accumulation: LLM tokens are accumulated into a buffer
  2. Boundary Detection: The validator's _chunking_function checks if enough text has accumulated
  3. Segment Extraction: When a boundary is found, the ready segment is extracted for validation
  4. Remainder Carry: Incomplete text is carried to the next accumulation cycle

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment