nemoguardrails.guardrails.api_engine

View as Markdown

Generic API engine for IORails, calling arbitrary REST endpoints via aiohttp with retry.

Module Contents

Classes

NameDescription
APIEngineWraps a single API endpoint and makes HTTP calls with retry support.
APIEngineErrorRaised when an API engine call fails.

Data

log

API

class nemoguardrails.guardrails.api_engine.APIEngine(
base_url: str,
endpoint: str,
api_key: typing.Optional[str] = None,
timeout_total: float = DEFAULT_TIMEOUT_TOTAL,
timeout_connect: float = DEFAULT_TIMEOUT_CONNECT,
max_attempts: int = DEFAULT_MAX_ATTEMPTS
)

Bases: BaseEngine

Wraps a single API endpoint and makes HTTP calls with retry support.

url
str

Full URL for the API endpoint.

nemoguardrails.guardrails.api_engine.APIEngine.call(
body: dict[str, typing.Any],
kwargs = {}
) -> dict
async

POST the JSON body to the configured endpoint and return the parsed response.

classmethod

Create an APIEngine from a JailbreakDetectionConfig.

class nemoguardrails.guardrails.api_engine.APIEngineError(
message: str,
endpoint: str,
status: int | None = None
)
Exception

Bases: Exception

Raised when an API engine call fails.

nemoguardrails.guardrails.api_engine.log = logging.getLogger(__name__)