nemoguardrails.server.experimental.provider.stream_policy
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
API
Build a classifier only after generic and typed-policy checks pass.
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.
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.
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.