core.response_utils
Response cleaning and JSON extraction utilities.
Uses json_repair for fault-tolerant parsing of LLM output that may
contain trailing commas, unquoted keys, or other common JSON mistakes.
Response cleaning and JSON extraction utilities.
Uses json_repair for fault-tolerant parsing of LLM output that may
contain trailing commas, unquoted keys, or other common JSON mistakes.
Extract JSON from text using fault-tolerant json_repair.
Handles markdown code blocks, trailing commas, unquoted keys, and
other common LLM JSON mistakes.
- Parameters:
text (str) – Response text that may contain JSON.
- Returns:
Parsed JSON object or None if no valid JSON found.
- Return type:
Any | None
-
clean_response(response)[source]
Process and validate a response, removing think tags and extracting JSON.
- Parameters:
response (Any) – The raw response from the AI client.
- Returns:
Cleaned response. If JSON is detected, returns the parsed object.
Otherwise returns the cleaned string with think tags removed.
- Return type:
Any
Functions
-
clean_response(response)[source]
Process and validate a response, removing think tags and extracting JSON.
- Parameters:
response (Any) – The raw response from the AI client.
- Returns:
Cleaned response. If JSON is detected, returns the parsed object.
Otherwise returns the cleaned string with think tags removed.
- Return type:
Any
-
extract_json(text)[source]
Extract JSON from text using fault-tolerant json_repair.
Handles markdown code blocks, trailing commas, unquoted keys, and
other common LLM JSON mistakes.
- Parameters:
text (str) – Response text that may contain JSON.
- Returns:
Parsed JSON object or None if no valid JSON found.
- Return type:
Any | None