nemoguardrails.server.api
Module Contents
Classes
Functions
Data
llm_rails_events_history_cache
API
Bases: BaseModel
Bases: BaseModel
Bases: FastAPI
Custom FastAPI subclass with additional attributes for Guardrails server.
Bases: Exception
Exception raised for errors in the configuration.
Format streaming chunks from LLMRails.stream_async() as SSE events.
Args: stream_iterator: AsyncIterator from stream_async() that yields str or dict chunks model_name: The model name to include in the chunks
Yields: SSE-formatted strings (data: {…}
)
Generates a cache key for the given config ids and model name.
Returns the rails instance for the given config id and model.
Parameters:
List of configuration IDs to load
The model name from the request (overrides config’s main model)
Check if a directory (or its ‘config’ subdirectory) contains a config.yml/yaml.
Update the main model in the RailsConfig.
If a model with type=“main” exists, it replaces it. Otherwise, adds it.
Validate request state shape before loading rails config.
At the public HTTP boundary, the only accepted non-empty dict state shape is Colang 1.0 transcript state: {“events”: […]}. Colang 2.0 has no safe public dict state shape.
Chat completion for the provided conversation.
TODO: add support for explicit state object.
Returns the list of available challenges for red teaming.
Returns the list of available rails configurations.
Register any additional challenges, if available at startup.
Return the list of models available from the configured provider.
Processes a single chunk from the stream.
Parameters:
A single chunk from the stream (can be str, dict, or other type).
The model name (not used in processing but kept for signature consistency).
Returns: Union[Any, ChunkError]
Union[Any, StreamingError]: StreamingError instance for errors or the original chunk.
Register additional challenges
Parameters:
The new challenges to be registered.
Registers a DataStore to be used by the server.
Register an additional logger
Start a thread that monitors the config folder for changes.