Basic streaming
Streaming with a guard class can be done by setting thestream parameter to True:
error_spans_in_output helper method on Guard. This will provide an up to date list of all ranges of text in the output so far that have failed validation.
Async streaming
In cases where concurrent network calls are happening (many LLM calls!) it may be beneficial to use an asynchronous LLM client. Guardrails also natively supports asynchronous streaming calls.Using validators with streaming
To stream validated output, you need only pass thestream=True flag through the guard function. This will return a generator that will yield GuardResult objects as they are processed.
on_fail types are supported with streaming.