RailsConfig
TheRailsConfig class represents the configuration for a guardrails application. It defines models, rails, prompts, and other settings.
Loading Configuration
from_path
Load a configuration from a directory or file path.Path to a directory containing configuration files (config.yml, .co files) or a single .co file.
The percentage of examples to use for testing.
A RailsConfig instance loaded from the specified path.
from_content
Create a configuration from YAML and Colang content strings.Colang (.co) file content as a string.
YAML configuration content as a string.
Configuration Fields
List of LLM model configurations. Each model has:
type: “main”, “embeddings”, “content_safety”, etc.engine: Provider name (“openai”, “nvidia_ai_endpoints”, etc.)model: Model name (“gpt-4o”, “llama-3.1-8b”, etc.)parameters: Additional parameters for the modelcache: Cache configuration for the model
Configuration for different types of rails:
input: Input rails configurationoutput: Output rails configurationretrieval: Retrieval rails configurationdialog: Dialog rails configurationtool_input: Tool input rails configurationtool_output: Tool output rails configurationconfig: Additional rail-specific configuration (fact checking, jailbreak detection, etc.)
List of custom prompts for specific tasks. Each prompt has:
task: The task IDcontent: The prompt content (for text completion)messages: List of messages (for chat completion)models: Optional list of models this prompt applies to
Mapping of canonical user message forms to example utterances.
Mapping of canonical bot message forms to example responses.
List of Colang flow definitions.
Natural language instructions for the LLM.
Documents for knowledge base/RAG.
The Colang version to use (“1.0” or “2.x”).
Whether to enable passthrough mode (direct LLM access without rails).
Whether streaming is enabled by default.
Custom configuration data for user-defined extensions.
Configuration for the knowledge base.
Configuration for tracing/telemetry.
Model Configuration
Rails Configuration
Prompts Configuration
Methods
model_dump
Export the configuration as a dictionary.model_dump_json
Export the configuration as a JSON string.Combining Configurations
You can combine multiple configurations using the+ operator: