Skip to main content

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:
Variables can include type hints and descriptions:

Extracting Variables

Use the extract_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:
  1. Missing Variables - All required variables must be provided
  2. Unexpected Variables - No extra variables allowed
  3. 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

Validate variables before using a prompt:
Include type hints in your prompts for better validation:
Type hints enable automatic validation and better documentation.
Provide defaults for optional variables:
Use descriptions to document variables:

Advanced: Variable Extraction from All Fields

Extract variables from all prompt fields (generator, system, critique):

Next Steps

Context Files

Work with file attachments and URLs

Listing Prompts

Browse and paginate through prompts

Error Handling

Handle validation and API errors

API Reference

Complete API documentation