Implementation:Guardrails ai Guardrails RC
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Settings |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
The RC dataclass represents the Guardrails runtime configuration loaded from the ~/.guardrailsrc file.
Description
This module defines the RC dataclass which reads and parses the user's .guardrailsrc configuration file from their home directory. The file uses a simple key=value format, one entry per line. The class handles:
- Boolean config parsing: Keys listed in
BOOL_CONFIGS(no_metrics,enable_metrics,use_remote_inferencing) are automatically converted to boolean values. - Quote stripping: Values wrapped in matching single or double quotes have the quotes removed.
- Legacy support: The deprecated
no_metricskey is backfilled intoenable_metricswith inverted logic for backwards compatibility. - Graceful fallback: If the
.guardrailsrcfile does not exist, an empty defaultRCinstance is returned.
The RC class extends Serializeable, providing from_dict deserialization support.
Usage
Use RC to access the user's Guardrails configuration. Call RC.load() to read and parse the configuration file, or RC.exists() to check if a configuration file is present. This is typically used internally by the framework to determine metrics and inferencing settings.
Code Reference
Source Location
- Repository: Guardrails
- File:
guardrails/classes/rc.py - Lines: 1-80
Signature
BOOL_CONFIGS = set(["no_metrics", "enable_metrics", "use_remote_inferencing"])
@dataclass
class RC(Serializeable):
id: Optional[str] = None
token: Optional[str] = None
enable_metrics: Optional[bool] = True
use_remote_inferencing: Optional[bool] = True
@staticmethod
def exists() -> bool:
@classmethod
def load(cls, logger: Optional[logging.Logger] = None) -> "RC":
Import
from guardrails.classes.rc import RC
I/O Contract
RC Fields
| Field | Type | Default | Description |
|---|---|---|---|
id |
Optional[str] |
None |
User or instance identifier. |
token |
Optional[str] |
None |
Authentication token for Guardrails services. |
enable_metrics |
Optional[bool] |
True |
Whether metrics collection is enabled. |
use_remote_inferencing |
Optional[bool] |
True |
Whether to use remote inferencing for validators. |
exists
| Return Type | Description |
|---|---|
bool |
True if ~/.guardrailsrc exists on disk; False otherwise.
|
load
| Parameter | Type | Default | Description |
|---|---|---|---|
logger |
Optional[logging.Logger] |
None |
Logger instance for warning on malformed lines. Defaults to the root logger. |
| Return Type | Description |
|---|---|
RC |
A populated RC instance. Returns a default instance with empty values if the file is not found.
|
Configuration File Format
The ~/.guardrailsrc file uses a simple key-value format:
id=my-user-id
token=my-secret-token
enable_metrics=true
use_remote_inferencing=false
Usage Examples
from guardrails.classes.rc import RC
# Check if configuration exists
if RC.exists():
config = RC.load()
print(f"Token: {config.token}")
print(f"Metrics enabled: {config.enable_metrics}")
print(f"Remote inferencing: {config.use_remote_inferencing}")
else:
print("No .guardrailsrc found, using defaults")
config = RC() # Uses default values
# Load with a custom logger
import logging
logger = logging.getLogger("my_app")
config = RC.load(logger=logger)
Related Pages
- Guardrails_ai_Guardrails_CLI_Validate - CLI command that may use RC settings for validation configuration
- Guardrails_ai_Guardrails_CLI_Watch - CLI command that reads settings influenced by the RC configuration