Response Parsing¶
These functions parse and extract structured information from text, particularly useful for processing LLM responses.
parse_json¶
Parses a JSON string into a record or list.
Parameters:
text- A string containing valid JSON
Returns: The parsed JSON value (record or list).
let data = parse_json("{\"name\": \"test\", \"score\": 0.95}");
// data = {"name": "test", "score": 0.95}
extract_key¶
Extracts the value associated with a key from a text string. Useful for pulling structured information from LLM responses that contain key-value patterns.
Parameters:
text- A string to searchkey- The key name to look fordefault- A fallback value if the key is not found (optional, defaults to none)
Returns: The extracted value, or the default if not found.
extract_number¶
Extracts the first numeric value found in a text string.
Parameters:
text- A string potentially containing numbers
Returns: The first number found, or none if no number is present.
extract_sentiment¶
Classifies the sentiment of a text string using simple heuristics.
Parameters:
text- A string to analyze
Returns: A record with two fields:
"label"- One of"positive","negative", or"neutral""score"- A confidence score between 0 and 1