nemoguardrails.server.exception_handlers
nemoguardrails.server.exception_handlers
Module Contents
Functions
Data
API
Extract the client-facing message and the OpenAI error fields from an exception.
code and param come from the provider when it supplied them, and a
rate limit forwards its Retry-After so SDK backoff is not blind.
Render the shared OpenAI error envelope as a JSON HTTP response.
Read the upstream HTTP status off an exception, wherever that exception keeps it.
Return 400 for request/config combinations the caller can correct.
These carry an actionable message (for example “enable streaming output rails”), so they must not fall through to the 500 catch-all, which would both hide the message and invite an SDK retry.
Render HTTPException (404, 422 guards, upstream 502, etc.) as the error envelope.
exc.headers is forwarded because HTTP requires some of them (Allow
on 405, WWW-Authenticate on 401), and statuses that disallow a body get
an empty response rather than an envelope.
Catch-all for unexpected errors.
Map LLM and engine call failures to their upstream HTTP status.
Return 400 when a model fails to initialize from the configuration.
Return 422 for request body validation failures.
Only the field locations and messages are reported. str(exc) is the repr
of pydantic’s error list, which embeds the raw request body (prompts,
tokens, PII), so it must reach neither the client nor the server log.