core.prompt_utils

Prompt interpolation and JSON field extraction utilities.

Prompt interpolation and JSON field extraction utilities.

extract_json_field(data, path)[source]

Extract a value from JSON using dot notation path.

Supports: - Simple fields: “field_name” - Nested objects: “object.field” - Array indices: “array.0” - Combined: “object.array.0.field”

Parameters:
  • data (Any) – Parsed JSON data (dict or list)

  • path (str) – Dot-separated path to extract

Returns:

Extracted value as string, or empty string if not found

Return type:

str

interpolate_prompt(prompt, history, strict=False)[source]

Replace {{prompt_name.response}} patterns with actual content.

Parameters:
  • prompt (str) – Template containing {{}} patterns

  • history (dict[str, str]) – Dict mapping prompt_name to response text

  • strict (bool) – If True, raise ValueError on unknown references instead of silently replacing with empty string.

Returns:

Tuple of (resolved_prompt, set_of_interpolated_prompt_names)

Return type:

tuple[str, set[str]]

Functions

extract_json_field(data, path)[source]

Extract a value from JSON using dot notation path.

Supports: - Simple fields: “field_name” - Nested objects: “object.field” - Array indices: “array.0” - Combined: “object.array.0.field”

Parameters:
  • data (Any) – Parsed JSON data (dict or list)

  • path (str) – Dot-separated path to extract

Returns:

Extracted value as string, or empty string if not found

Return type:

str

interpolate_prompt(prompt, history, strict=False)[source]

Replace {{prompt_name.response}} patterns with actual content.

Parameters:
  • prompt (str) – Template containing {{}} patterns

  • history (dict[str, str]) – Dict mapping prompt_name to response text

  • strict (bool) – If True, raise ValueError on unknown references instead of silently replacing with empty string.

Returns:

Tuple of (resolved_prompt, set_of_interpolated_prompt_names)

Return type:

tuple[str, set[str]]