> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Safe Format • AI Agents Framework

> safe_format: Safely format a string template, preserving JSON-like curly braces.

# safe\_format

<div className="flex items-center gap-2">
  <Badge color="teal">Function</Badge>
</div>

> This function is defined in the [**agents\_generator**](../modules/agents_generator) module.

Safely format a string template, preserving JSON-like curly braces.

This handles cases where templates contain Gutenberg block syntax like
\{"level":2} which would cause KeyError with standard .format().

Uses a two-pass approach:

1. Escape all \{\{ and }} (already escaped braces)
2. Only substitute known variable placeholders

## Signature

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
def safe_format(template: str) -> str
```

## Parameters

<ParamField query="template" type="str" required={true}>
  String template with \{variable} placeholders \*\*kwargs: Variable substitutions to apply
</ParamField>

### Returns

<ResponseField name="Returns" type="str">
  Formatted string with variables substituted and JSON preserved
</ResponseField>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
>>> safe_format('Use <!-- wp:heading {"level":2} --> for {topic}', topic='AI')
    'Use <!-- wp:heading {"level":2} --> for AI'
```

## Uses

* `match.group`
* `re.sub`

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai/praisonai/agents_generator.py#L85">
  `praisonai/agents_generator.py` at line 85
</Card>
