Principle:Spcl Graph of thoughts Keyword Counting Prompt Design
| Knowledge Sources | |
|---|---|
| Domains | Prompt_Engineering, Keyword_Counting |
| Related Implementations | Implementation:Spcl_Graph_of_thoughts_KeywordCountingPrompter |
| Last Updated | 2026-02-14 |
Overview
Domain-specific prompt engineering pattern for decompose-count-aggregate-validate reasoning over keyword frequency counting problems.
Description
The Keyword Counting Prompt Design principle defines a comprehensive family of prompt templates for counting the frequency of country names in text passages. This is the most elaborate example in the GoT framework, supporting seven distinct reasoning approaches: IO, CoT, ToT, ToT2, GoT4, GoT8, and GoTx. Each approach uses a different combination of the prompt templates to achieve its goals.
Prompt Strategy by Reasoning Approach
Input-Output (IO): A single prompt (count_prompt) asks the LLM to count all country name frequencies in the full passage and output a JSON dictionary. Few-shot examples demonstrate the expected format.
Chain-of-Thought (CoT): The prompt (count_prompt_cot) instructs the LLM to decompose the passage into paragraphs, count frequencies per paragraph, and combine them -- all within one response. The <Approach> section provides explicit steps.
Tree-of-Thought (ToT/ToT2): Uses the CoT prompt for the initial generation, then applies tot_improve_prompt to iteratively refine incorrect frequency dictionaries. The improvement prompt presents both the original text and an incorrect dictionary, asking the LLM to compare and fix frequencies.
GoT4 (4-paragraph split): Three-phase approach:
- Split:
got_split_promptasks the LLM to split the text into 4 equal-length paragraphs as JSON. - Count:
count_prompt_cotis applied to each paragraph independently. - Aggregate:
got_aggregate_promptmerges two frequency dictionaries by summing counts. - Validate & Improve:
got_improve_aggregate_promptcorrects incorrect aggregations by showing both input dictionaries and the erroneous combined result.
GoT8 (8-paragraph split): Same pattern as GoT4 but uses got_split_prompt2 to produce 8 paragraphs, resulting in a deeper aggregation tree (3 levels of pairwise merges).
GoTx (per-sentence split): The most fine-grained approach. Uses got_split_prompt3 to split text into individual sentences, then applies count_prompt_sentence (a simpler prompt optimized for single sentences with a word-by-word iteration approach) to each. Improvement uses sentence_improve_prompt tailored for short text fragments.
Key Design Patterns
- JSON output format: All counting prompts require output as a JSON dictionary (
Template:"country": frequency, ...). Double braces{{ }}are used in templates to escape Python format strings. - Graduated complexity: Few-shot examples increase from simple (1-2 countries) to complex (12 countries, repeated occurrences) to calibrate LLM behavior.
- Improvement prompts: Both
tot_improve_promptandsentence_improve_promptinclude a "Reason" field in examples that demonstrates the explicit error analysis the LLM should perform. - Aggregation prompt:
got_aggregate_promptprovides step-by-step instructions for dictionary merging, making the addition logic explicit. - Validation-aware aggregation:
got_improve_aggregate_promptshows the LLM both input dictionaries and the incorrect merge, asking it to verify each country's sum and fix errors.
Prompt Template Inventory
| Template | Lines | Purpose | Target Method |
|---|---|---|---|
count_prompt |
165-219 | Full-text frequency counting | IO |
count_prompt_cot |
221-349 | CoT-style paragraph decomposition | CoT, ToT (initial), GoT4/GoT8 (phase 1) |
count_prompt_sentence |
351-408 | Sentence-level word-by-word counting | GoTx (phase 1) |
tot_improve_prompt |
410-503 | Fix incorrect frequency dictionary | ToT, GoT4/GoT8 (phase 2) |
sentence_improve_prompt |
505-574 | Fix incorrect dictionary for single sentence | GoTx (phase 2) |
got_split_prompt |
576-599 | Split text into 4 paragraphs (JSON) | GoT4 (phase 0) |
got_split_prompt2 |
601-633 | Split text into 8 paragraphs (JSON) | GoT8 (phase 0) |
got_split_prompt3 |
635-659 | Split text into individual sentences (JSON) | GoTx (phase 0) |
got_aggregate_prompt |
661-678 | Merge two frequency dictionaries | GoT4/GoT8/GoTx (aggregation) |
got_improve_aggregate_prompt |
680-729 | Fix incorrect dictionary merge | GoT4/GoT8/GoTx (validation) |
Related Pages
- Implementation:Spcl_Graph_of_thoughts_KeywordCountingPrompter -- Concrete Python class implementing this principle
- Principle:Spcl_Graph_of_thoughts_Keyword_Counting_Response_Parsing -- Companion parsing principle
- Workflow:Spcl_Graph_of_thoughts_GoT_Keyword_Counting_Pipeline -- End-to-end workflow using these prompts