Nyraxis/ docs
Guides
Developer documentation

Enforcement

Choose failure behavior and understand exactly where an SDK check can stop a call.

Pre-call enforcement evaluates extracted input before a supported model method makes its provider request. It does not authorize arbitrary tools or inspect every generated token. Configure and test each boundary deliberately.

Python setup

Application startup
import os
import nyraxis_sdk

nyraxis_sdk.init(
    api_key=os.environ["NYRAXIS_API_KEY"],
    base_url=os.environ["NYRAXIS_BASE_URL"],
    agent_name="support-agent",
    enforce=True,
    enforce_fail_open=False,
    enforce_require_complete=True,
    enforce_timeout_s=15,
    enforce_cache_ttl_s=0,
)

Call shutdown() when synchronous application work ends, or await shutdown_async() in an asynchronous lifecycle. Choose the timeout from your actual backend latency; 15 seconds above is a configuration example, not a response-time guarantee.

Supported methods

PackageImplemented input interception
Python openaiSupported Chat Completions, legacy Completions, and Responses create paths, including covered async variants.
Python anthropicSupported Messages create methods, including covered async variants.
Python LangChainSupported BaseChatModel.invoke / ainvoke text extraction; verify your concrete provider and streaming path.
Node OpenAIenforce(client, options) wraps supported OpenAI Chat Completions, Completions, and Responses create paths.
Other providers/frameworksUse explicit evaluation at the application boundary. Native interception is not implied.

These are implementation boundaries, not a claim that every SDK version, modality, structured tool message, or method is covered. Integration coverage identifies the live verified subset. System/developer prompts and unsupported image/audio content are not automatically covered by the text extractors.

Handle outcomes

Gate a supported model call
from openai import OpenAI
import nyraxis_sdk

model = OpenAI()

def reply(message: str) -> str:
    try:
        response = model.chat.completions.create(
            model="gpt-4o-mini",
            messages=[{"role": "user", "content": message}],
        )
        return response.choices[0].message.content or ""
    except nyraxis_sdk.NyraxisBlockedError:
        return "This request was blocked by the configured policy."

This function assumes the startup configuration above has already run. Network, invalid-response, and incomplete-check errors must be handled by your service's unavailable path; they must not continue to a second unguarded model call.

Fail-open and completion settings

ConfigurationEffect
enforce_fail_open=TrueGenuine evaluator transport failures may let the provider call proceed. This is the Python compatibility default.
enforce_fail_open=FalseTransport failure propagates and stops the intercepted call.
enforce_require_complete=TrueAn allowed result with incomplete status or errors is rejected.
enforce_cache_ttl_s=0Always get a fresh decision; useful for policy-edit retests.

Fail-closed transport behavior alone does not require a complete detector result. Set both options for required checks. A malformed decision or explicit access denial is not a transport fail-open decision.

Warning versus monitoring

A configured warning policy can report a finding and allow the request. A blocking policy denies it. Node additionally has wrapper behavior: "monitor", which does not enforce the returned decision; keep that separate from backend policy mode and API depth. Python tracing without enforce=True observes calls but does not install input enforcement.

Tool and output boundaries

The LangGraph example explicitly checks a read-only tool's result before feeding it back to the model. That check cannot prevent the lookup itself. Authorize a side-effecting tool before execution.

To prevent disclosure in a generated answer, buffer it, call evaluate(input=..., output=...), validate completion, and return it only if allowed. Checking after streaming has sent tokens is observation, not prevention.

Measure and test

Count actual provider calls for allowed, blocked, incomplete, unavailable, cached, and malformed-response cases. Repeat after a policy change with caching disabled. Measure warm and cold latency with your network and selected detectors; there is no universal overhead figure for all deployments.

On this page