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 Prompt Design

From Leeroopedia
Knowledge Sources
Domains Prompt_Engineering, Sorting
Related Implementations Implementation:Spcl_Graph_of_thoughts_SortingPrompter
Last Updated 2026-02-14

Overview

Domain-specific prompt engineering pattern for decompose-sort-merge reasoning over list sorting problems.

Description

The Sorting Prompt Design principle defines how prompts are constructed to guide an LLM through sorting a list of integers (0-9) using different reasoning strategies. The design centers on a family of prompt templates, each tailored to a specific reasoning approach (IO, CoT, ToT, GoT), all sharing the common goal of producing a correctly sorted list from an unsorted input.

Prompt Strategy by Reasoning Approach

Input-Output (IO): The simplest approach. A single prompt asks the LLM to sort the entire list in one pass. The prompt provides few-shot examples of increasing list sizes (16, 32, 64 elements) and instructs the model to output only the sorted list with no intermediate reasoning.

Chain-of-Thought (CoT): The prompt explicitly guides the LLM through a multi-step decomposition within a single response. It instructs the model to:

  1. Split the list into two to four unsorted sublists of equal length.
  2. Sort each sublist independently.
  3. Merge the sorted sublists using the merge sort algorithm.

The final answer must be prefixed with "Output: " to enable reliable parsing.

Tree-of-Thought (ToT): Uses the same IO sort prompt for the initial pass, then applies an improvement prompt to refine incorrect results. The improvement prompt presents both the original unsorted list and the incorrectly sorted attempt, instructing the LLM to compare digit frequencies and correct mismatches.

Graph-of-Thought (GoT): The most structured approach. It uses three prompt phases:

  1. Split prompt: Asks the LLM to decompose the input list into 2 sublists of equal length, outputting JSON with keys "List 1" and "List 2".
  2. Sort prompt: Reuses the IO sort prompt on each individual sublist.
  3. Merge prompt: Asks the LLM to merge two sorted sublists into one sorted list, following a step-by-step merge sort approach.

After merging, an improvement prompt may be applied if the result contains errors.

Shared Design Patterns

All prompt templates follow consistent structural conventions:

  • <Instruction> tags delimit the core task directive.
  • <Examples> tags contain few-shot demonstrations with increasing complexity.
  • <Approach> tags (when present) provide step-by-step algorithmic guidance.
  • Prompts explicitly state constraints such as "Output only the sorted list of numbers, no additional text."
  • Input placeholders use Python string formatting: {input}, {length}, {incorrectly_sorted}.

Key Design Decisions

  • The improvement prompt (used by both ToT and GoT) asks the LLM to compare per-digit frequencies between the input and the incorrect output, making the correction task explicit rather than relying on the model to re-sort from scratch.
  • The GoT split prompt requires JSON output with named keys, enabling deterministic parsing of sublists for parallel processing.
  • Few-shot examples are carefully chosen to scale with the problem size (16, 32, 64 elements), giving the model relevant reference points.

Related Pages

Page Connections

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