Skip to main content

safe_format

Function
This function is defined in the 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

Parameters

str
required
String template with {variable} placeholders **kwargs: Variable substitutions to apply

Returns

str
Formatted string with variables substituted and JSON preserved

Usage

Uses

  • match.group
  • re.sub

Source

View on GitHub

praisonai/agents_generator.py at line 85