Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Spcl Graph of thoughts Sorting Response Parsing

From Leeroopedia
Revision as of 17:21, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Spcl_Graph_of_thoughts_Sorting_Response_Parsing.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 receives phase=1, a part identifier, and the unsorted_sublist for 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:

  1. Splits the response by newlines and looks for lines containing "Output".
  2. Extracts the list between brackets from the last matching line.
  3. Merges the unsorted_sublist fields from both input states by concatenation (removing the closing bracket of the first and opening bracket of the second).
  4. Sorts input states by their part identifier 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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment