Principle:Guardrails ai Guardrails Validator Streaming Support
| Knowledge Sources | |
|---|---|
| Domains | Streaming, Validation |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
A streaming adaptation principle that allows validators to define custom text segmentation strategies for incremental validation of streaming LLM output.
Description
Validator Streaming Support extends the validation interface with a _chunking_function that determines how accumulated streaming text is segmented for validation. The default implementation uses sentence boundary detection, splitting text at sentence-ending punctuation. Custom validators can override this to validate at word boundaries, paragraph boundaries, fixed-length segments, or any application-specific boundary.
The chunking function receives the accumulated text buffer and returns either an empty list (not enough text yet) or a two-element list: the segment ready for validation and the remaining text to carry forward.
Usage
Override _chunking_function in custom validators when the default sentence-based chunking is not appropriate for your validation logic. For example, a word-count validator might chunk at word boundaries, while a paragraph-level validator might chunk at double newlines.
Theoretical Basis
The chunking contract:
# Abstract interface
def _chunking_function(self, chunk: str) -> List[str]:
# Returns empty list: not enough text accumulated
# Returns [segment, remainder]: segment ready for validation
# Default: sentence boundary detection
# Custom: any segmentation strategy
...