Variable Handling
Claro prompts support variables that can be dynamically replaced with values. Learn how to extract, validate, and use variables.Understanding Variables
Variables in prompts use double curly brace syntax:Extracting Variables
Use theextract_variables() method to find all variables in a prompt:
Variable Information
Each extracted variable contains:Variable Types
Claro supports several variable types:String Variables
Number Variables
Boolean Variables
Array Variables
Object Variables
Validating Variables
Validate variable values before using them:Validation Rules
The validator checks:- Missing Variables - All required variables must be provided
- Unexpected Variables - No extra variables allowed
- Type Mismatches - Values must match declared types
Using Prompts as Templates
Replace variables with actual values:Complete Example
Type Safety with Python
For better type safety, use TypedDict:Dynamic Variable Discovery
Discover variables at runtime:Best Practices
Always Validate Variables
Always Validate Variables
Validate variables before using a prompt:
Use Type Hints in Prompts
Use Type Hints in Prompts
Include type hints in your prompts for better validation:Type hints enable automatic validation and better documentation.
Handle Missing Variables Gracefully
Handle Missing Variables Gracefully
Provide defaults for optional variables:
Document Variable Usage
Document Variable Usage
Use descriptions to document variables: