> ## Documentation Index
> Fetch the complete documentation index at: https://snowglobe.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Stream validated output

> Learn how to stream validated output from LLMs using Guardrails

To stream validated output, pass the `stream=True` flag through the `guard` function. This will return a generator that yields `GuardResult` objects as they are processed.

```python theme={null}
from guardrails import Guard
import os

# Set your OpenAI API key
# os.environ['OPENAI_API_KEY'] = ""

guard = Guard()

stream_chunk_generator = guard(
    messages=[{"role":"user", "content":"How many moons does Jupiter have?"}],
    model="gpt-3.5-turbo",
    stream=True
)

# Print the validated output as it is processed
for chunk in stream_chunk_generator:
    print(f"{chunk.validated_output}")
```

## Using validators with streaming

Using validators with streaming works the same way. Note that not all `on_fail` types are supported with streaming. See the full list in the [error remediation concepts doc](/guardrails/docs/concepts/error-remediation).

```bash theme={null}
guardrails hub install hub://guardrails/profanity_free
```

```python theme={null}
from guardrails import Guard
from guardrails.hub import ProfanityFree
import os

# Set your OpenAI API key
# os.environ['OPENAI_API_KEY'] = ""

guard = Guard().use(ProfanityFree())

stream_chunk_generator = guard(
    messages=[{"role":"user", "content":"How many moons does Jupiter have?"}],
    model="gpt-3.5-turbo",
    stream=True
)

# Print the validated output as it is processed
for chunk in stream_chunk_generator:
    print(f"{chunk.validated_output}")
```

## Learn more

Read more about streaming in our concept docs:

* [Streaming](/guardrails/docs/concepts/streaming)
* [Async stream-validate LLM responses](/guardrails/docs/concepts/async-streaming)
* [Streaming structured data](/guardrails/docs/concepts/streaming-structured-data)
