nemoguardrails.server.experimental.provider.contract_export
nemoguardrails.server.experimental.provider.contract_export
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
API
Export supported classifier declarations, never instantiate or serialize protocol hooks.
Describe a typed event rule without dropping unsupported selection or fallback semantics.
Import one trusted module attribute for the CLI, without discovery or eval.
Reject drift between supported runtime bindings and exported field policy.
Reject custom stream validation that cannot be described by field policy.
Require declarative strict-boolean selection with a representable default.
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:
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.
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.