Expand description
Robust JSON parsing utilities
Handles malformed JSON from streaming LLM responses:
- Escapes raw control characters inside strings
- Doubles backslashes before invalid escape characters
- Repairs incomplete JSON from streaming responses
Functions§
- extract_
error_ message - Extract the error message from an assistant message that may have malformed JSON in its error field.
- parse_
json_ with_ repair - Parse JSON with automatic repair of common malformations.
- parse_
sse_ data - Parse a streaming SSE data field as JSON, with robust error handling.
Returns
Nonefor non-data lines or unparseable content. - parse_
streaming_ json - Attempts to parse potentially incomplete JSON from a streaming response.
- repair_
json - Repairs malformed JSON string literals by: