Custom Configuration Data for NeMo Guardrails
The custom_data field in config.yml allows you to pass additional configuration to your custom initialization code and actions.
Defining Custom Data
Add a custom_data section to your config.yml:
Accessing in config.py
Access custom data in your init function:
Accessing in Actions
You can also access custom data directly in actions via the config parameter:
Sensitive Configuration
For sensitive values like API keys, use the api_key_env_var field on model configurations or load environment variables in your init() function:
config.py:
The custom_data field in config.yml uses standard YAML parsing and does not support inline environment variable substitution (e.g., ${VAR}). Load sensitive values from environment variables in your init() function instead.
Best Practices
-
Use environment variables for secrets: Never hardcode API keys or passwords.
-
Provide defaults: Use
.get("key", default)for optional values. -
Document your custom_data schema: Add comments in config.yml explaining expected fields.
-
Validate configuration: Check required fields in
init()and raise clear errors.