parsing
parsing
¶
Response parsing utilities.
extract_json(text)
¶
Extract a JSON object from text that may contain surrounding prose.
Tries in order:
1. Direct json.loads (text is pure JSON)
2. Fenced code block (json ...)
3. First { ... } substring
Raises ValueError if no valid JSON found.
Source code in autochecklist/utils/parsing.py
parse_checklist_items(response, max_items=None)
¶
Parse checklist items from LLM response.
Supports multiple formats: - [[item]] bracketed format (TICK, checklist-effectiveness-study) - Numbered list: "1. Question?" - Bulleted list: "- Question?" - RLCF weighted format: "- Question? (weight)"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
str
|
Raw LLM response text |
required |
max_items
|
int
|
Maximum items to return |
None
|
Returns:
| Type | Description |
|---|---|
List[ChecklistItem]
|
List of ChecklistItem objects |
Source code in autochecklist/utils/parsing.py
parse_yes_no_answers(response, num_questions)
¶
Parse yes/no answers from LLM response.
Supports formats: - "Q1: Yes" or "Q1: No" - "1. Yes" or "1. No" - JSON with "answer" field
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
str
|
Raw LLM response text |
required |
num_questions
|
int
|
Expected number of questions |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[int, str, Optional[str]]]
|
List of (question_index, answer, reasoning) tuples |