Skip to navigation

nemoguardrails.server.experimental.provider.contract_export

View as MarkdownOpen in Claude

Export guard contracts from trusted Python endpoint declarations.

Provider integrations supply an endpoint and document identity, not exporter implementations. Model annotations describe payload policy; endpoint metadata describes the route and rejection codes. Exporting does not enable runtime features or serialize arbitrary Python validation and transport behavior.

The CLI imports one explicitly selected module attribute. That import executes Python code: use only trusted local endpoint declarations, never references from requests or untrusted documents. YAML and JSON Schema tooling is loaded only by the CLI; runtime endpoint construction does not depend on this module.

Module Contents

Functions

NameDescription
_export_streamExport supported classifier declarations, never instantiate or serialize protocol hooks.
_export_stream_eventDescribe a typed event rule without dropping unsupported selection or fallback semantics.
_load_endpointImport one trusted module attribute for the CLI, without discovery or eval.
_validate_policy_bindingReject drift between supported runtime bindings and exported field policy.
_validate_stream_modelReject custom stream validation that cannot be described by field policy.
_validate_stream_selectorRequire declarative strict-boolean selection with a representable default.
_validator_function-
export_guard_contractDescribe the payload and stream policy actually bound to an endpoint.
mainValidate and emit a guard contract, or check an artifact for exact drift.

API

nemoguardrails.server.experimental.provider.contract_export._export_stream(
) -> dict[str, typing.Any]

Export supported classifier declarations, never instantiate or serialize protocol hooks.

nemoguardrails.server.experimental.provider.contract_export._export_stream_event(
) -> dict[str, typing.Any]

Describe a typed event rule without dropping unsupported selection or fallback semantics.

nemoguardrails.server.experimental.provider.contract_export._load_endpoint(
reference: str

Import one trusted module attribute for the CLI, without discovery or eval.

nemoguardrails.server.experimental.provider.contract_export._validate_policy_binding(
direction: typing.Literal['request', 'response']

Reject drift between supported runtime bindings and exported field policy.

nemoguardrails.server.experimental.provider.contract_export._validate_stream_model(
) -> None

Reject custom stream validation that cannot be described by field policy.

nemoguardrails.server.experimental.provider.contract_export._validate_stream_selector(
) -> None

Require declarative strict-boolean selection with a representable default.

nemoguardrails.server.experimental.provider.contract_export._validator_function(
validator: typing.Any
) -> typing.Any
nemoguardrails.server.experimental.provider.contract_export.export_guard_contract(
) -> dict[str, typing.Any]

Describe the payload and stream policy actually bound to an endpoint.

No files are read or written. The CLI separately validates the document format; neither step proves upstream compatibility or runtime equivalence.

Parameters:

endpoint
GuardedJsonEndpoint

GuardedJsonEndpoint — A trusted endpoint with policy-annotated request and response models and their runtime bindings.

Returns: dict[str, Any]

A fresh document with payload schemas, profile, endpoint labels, and

Raises:

  • TypeError: The endpoint or its models do not support policy export.
  • ValueError: Bound coverage, extraction, replacement, or stream selection disagrees with the field policy, or a schema construct is unsupported.
nemoguardrails.server.experimental.provider.contract_export.main() -> None

Validate and emit a guard contract, or check an artifact for exact drift.

The endpoint argument imports trusted Python code. With —output, create parent directories and overwrite the selected file. With —check, leave files untouched and exit with status 1 on missing or differing content. With neither option, write YAML to stdout. Invalid declarations fail before file writes.