Principle:Spcl Graph of thoughts Sorting Response Parsing
| Knowledge Sources | |
|---|---|
| Domains | Response_Parsing, Sorting |
| Related Implementations | Implementation:Spcl_Graph_of_thoughts_SortingParser |
| Last Updated | 2026-02-14 |
Overview
Domain-specific parsing pattern for extracting sorted list results from LLM text responses.
Description
The Sorting Response Parsing principle defines how raw LLM text output is transformed into structured thought state dictionaries containing sorted (or partially sorted) lists. The parser must handle multiple response formats depending on the reasoning method and execution phase, and degrade gracefully when the LLM produces malformed output.
Parsing Strategy by Operation Type
Generate Parsing (parse_generate_answer): Handles two fundamentally different response formats depending on the execution phase:
- GoT Phase 0 (Split): The LLM returns a JSON object with keys like "List 1" and "List 2", each containing a sublist. The parser extracts the JSON between the first
{and last}, deserializes it, and creates a new thought state for each sublist. Each state receivesphase=1, apartidentifier, and theunsorted_sublistfor later reference. - All other methods/phases: The LLM returns a sorted list as text. The parser splits by newlines, filters for lines containing
[and], searches for lines containing "Output" (preferring the last one), and extracts the list substring between brackets.
Aggregation Parsing (parse_aggregation_answer): Processes the result of merging two sorted sublists. The parser:
- Splits the response by newlines and looks for lines containing "Output".
- Extracts the list between brackets from the last matching line.
- Merges the
unsorted_sublistfields from both input states by concatenation (removing the closing bracket of the first and opening bracket of the second). - Sorts input states by their
partidentifier to maintain deterministic ordering.
Error Handling Patterns
The parser follows a defensive strategy:
- If no line contains brackets, it attempts to wrap each line in brackets and parse with
string_to_list. - If all parsing fails, it logs a warning and returns an empty list
"[]". - Multiple answers on separate lines produce a warning, and only the first valid answer is used.
- JSON parse errors (for split results) are caught and logged, resulting in no new states for that response.
Phase Transitions
The parser manages thought state phase transitions:
- Split responses (phase 0) produce states with
phase=1(ready for individual sorting). - Sort responses (phase 1 and non-GoT) produce states with
phase=2(ready for merging or refinement). - These phase values drive the prompter to select the correct prompt template in subsequent operations.
Related Pages
- Implementation:Spcl_Graph_of_thoughts_SortingParser -- Concrete Python class implementing this principle
- Principle:Spcl_Graph_of_thoughts_Sorting_Prompt_Design -- Companion prompt design principle
- Workflow:Spcl_Graph_of_thoughts_GoT_Sorting_Pipeline -- End-to-end workflow using this parsing