Structured Output Parser
Parse structured key-value output from an LLM response.
LLMs often produce structured output with labeled fields. Parse a response into a dictionary where each line has the format "Key: Value".
Input:
- Multi-line text (each line is "Key: Value")
- Last line: comma-separated list of required keys
Output: For each required key (in order given), print the value. Print "MISSING" for keys not found.
Matching is case-insensitive for keys. Extra whitespace should be stripped.
Example
Name: Alice Age: 30 City: New York Name,Age,Email
Alice 30 MISSING
- The input is parsed into a dictionary with case-insensitive keys, resulting in:
name: Alice,age: 30,city: New York - The last line is split into a list of required keys:
Name,Age,Email - For each required key, the corresponding value is looked up in the dictionary, with case-insensitive matching, and printed:
AliceforName,30forAge - Since
Emailis not found in the dictionary,MISSINGis printed for that key
Constraints
- Key matching is case-insensitive
- Strip whitespace from keys and values
- Lines without ":" are skipped
- Required keys are comma-separated on the last input line