Skip to main content

RailsConfig

The RailsConfig 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.
str
required
Path to a directory containing configuration files (config.yml, .co files) or a single .co file.
float
default:"0.0"
The percentage of examples to use for testing.
RailsConfig
A RailsConfig instance loaded from the specified path.

from_content

Create a configuration from YAML and Colang content strings.
Optional[str]
Colang (.co) file content as a string.
Optional[str]
YAML configuration content as a string.

Configuration Fields

List[Model]
default:"[]"
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 model
  • cache: Cache configuration for the model
Rails
Configuration for different types of rails:
  • input: Input rails configuration
  • output: Output rails configuration
  • retrieval: Retrieval rails configuration
  • dialog: Dialog rails configuration
  • tool_input: Tool input rails configuration
  • tool_output: Tool output rails configuration
  • config: Additional rail-specific configuration (fact checking, jailbreak detection, etc.)
List[TaskPrompt]
default:"[]"
List of custom prompts for specific tasks. Each prompt has:
  • task: The task ID
  • content: The prompt content (for text completion)
  • messages: List of messages (for chat completion)
  • models: Optional list of models this prompt applies to
Dict[str, List[str]]
default:"{}"
Mapping of canonical user message forms to example utterances.
Dict[str, List[str]]
default:"{}"
Mapping of canonical bot message forms to example responses.
List[dict]
default:"[]"
List of Colang flow definitions.
List[Instruction]
default:"[]"
Natural language instructions for the LLM.
List[Document]
default:"[]"
Documents for knowledge base/RAG.
str
default:"1.0"
The Colang version to use (“1.0” or “2.x”).
bool
default:"False"
Whether to enable passthrough mode (direct LLM access without rails).
bool
default:"False"
Whether streaming is enabled by default.
dict
default:"{}"
Custom configuration data for user-defined extensions.
KnowledgeBaseConfig
Configuration for the knowledge base.
TracingConfig
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: