strip_json_fence

View as MarkdownOpen in Claude

Unwrap ```json ... ``` fencing. The chat engine hands the model’s answer back verbatim, fence and all, where the voice engine parses it first. Text without a fence is returned trimmed.

Parameters

text
strRequired

The raw string, fenced or not.

Returns

str — The content with any opening and closing fence removed and whitespace trimmed.

Example

import json
from signalwire.core.post_prompt import strip_json_fence
summary = json.loads(strip_json_fence('```json\n{"intent": "booking"}\n```'))
print(summary["intent"]) # booking

Part of the post-prompt normalization module.