> This page is for version Latest (default).
> For other versions, use one of these documentation indexes:
> - Latest (default): https://docs.nvidia.com/nemo/guardrails/latest/llms.txt
> - v0.25.0: https://docs.nvidia.com/nemo/guardrails/v0.25.0/llms.txt
> - v0.24.1: https://docs.nvidia.com/nemo/guardrails/v0.24.1/llms.txt
> - v0.24.0: https://docs.nvidia.com/nemo/guardrails/v0.24.0/llms.txt
> - v0.23.0: https://docs.nvidia.com/nemo/guardrails/v0.23.0/llms.txt
> - v0.22.0: https://docs.nvidia.com/nemo/guardrails/v0.22.0/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/guardrails/llms.txt.

# nemoguardrails.server.experimental.provider.stream_policy

Derive streaming metadata from typed projection fields and event rules.

Field policy declares the guarded text location; StreamEventRule declares event
selection, roles, and missing-text handling. These helpers remove duplicate
inventories without inferring provider lifecycle behavior or upstream coverage.
They operate on trusted framework declarations, not user-supplied schemas.

## Module Contents

### Functions

| Name                                                                                                                          | Description                                                                   |
| ----------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| [`build_policy_stream_classifier`](#nemoguardrails-server-experimental-provider-stream_policy-build_policy_stream_classifier) | Build a classifier only after generic and typed-policy checks pass.           |
| [`stream_shape_coverage`](#nemoguardrails-server-experimental-provider-stream_policy-stream_shape_coverage)                   | Collect event shapes by role, including fallbacks and opaque transport.       |
| [`stream_text_path`](#nemoguardrails-server-experimental-provider-stream_policy-stream_text_path)                             | Derive one named string or nullable-string subject from typed guarded fields. |
| [`validate_stream_policy`](#nemoguardrails-server-experimental-provider-stream_policy-validate_stream_policy)                 | Require a typed classifier's runtime bindings to agree with field policy.     |

### API

```python
nemoguardrails.server.experimental.provider.stream_policy.build_policy_stream_classifier(
    definition: nemoguardrails.server.experimental.provider.stream_classifier.StreamClassifierDefinition
) -> nemoguardrails.server.experimental.provider.stream_classifier.StreamClassifier
```

Build a classifier only after generic and typed-policy checks pass.

```python
nemoguardrails.server.experimental.provider.stream_policy.stream_shape_coverage(
    rules: tuple[nemoguardrails.server.experimental.provider.stream_classifier.StreamEventRule, ...],
    sentinels: tuple[tuple[bytes, str], ...] = (),
    non_data_shape: str | None = None
) -> nemoguardrails.server.experimental.provider.stream.StreamShapeCoverage
```

Collect event shapes by role, including fallbacks and opaque transport.

A shape shared by different roles is rejected by StreamShapeCoverage.
Selection and fallback consistency are checked by build_stream_classifier;
deriving coverage does not replace that validation or prove provider-wide
event coverage.

```python
nemoguardrails.server.experimental.provider.stream_policy.stream_text_path(
    model: type[nemoguardrails.server.experimental.provider.projection_policy.PolicyModel]
) -> nemoguardrails.server.experimental.provider.stream_classifier.StreamTextPath
```

Derive one named string or nullable-string subject from typed guarded fields.

Follow guarded models, nullable model containers, and lists that allow at
most one item, or heterogeneous arrays with an explicit ObjectPolicy.variant,
without schema generation, so unrelated field types cannot
affect the binding. Unlike buffered extraction, empty arrays, null
containers, and null text are valid: the event rule decides whether absent
text is rejected or classified as metadata. This function only derives the
path; it does not validate an event or choose its role.

**Raises:**

* `ValueError`: The declaration has no unique text subject, an array that
  may hold more than one item, an unsupported subject type, a union
  container, a recursive path, or a replacement blocker that is
  not a reviewed sibling field. Object-union selectors require
  disjoint declared variants with one bounded text-bearing branch.

```python
nemoguardrails.server.experimental.provider.stream_policy.validate_stream_policy(
    definition: nemoguardrails.server.experimental.provider.stream_classifier.StreamClassifierDefinition | nemoguardrails.server.experimental.provider.stream_classifier.StreamClassifier
) -> None
```

Require a typed classifier's runtime bindings to agree with field policy.

Text-bearing rules must follow the unique assistant subject derived from
guarded fields. Non-text rules cannot hide a declared subject. Coverage
must describe exactly the bound rules and transport shapes. This validates
the derivable typed subset; custom selectors and handwritten classifiers
can use the lower-level runtime interfaces but are not implicitly exportable.
No schemas are generated and no protocol hooks are instantiated.