Principle:Spcl Graph of thoughts Validity Filtering
| Knowledge Sources | |
|---|---|
| Domains | Graph_Reasoning, Thought_Operations |
| Last Updated | 2026-02-14 |
| Implemented By | Implementation:Spcl_Graph_of_thoughts_KeepValid_Operation |
Overview
Filtering pattern that retains only valid thoughts from predecessors, passing through unvalidated thoughts as well.
Description
The KeepValid operation is a boolean-based filtering mechanism in the Graph of Thoughts framework that retains thoughts based on their validation status. It keeps thoughts that either pass validation (valid == True) or have not been validated at all (validated == False). Thoughts that have been explicitly validated and found invalid (validated == True and valid == False) are discarded.
Key characteristics:
- Filtering condition: Keeps thoughts where
not thought.validated or thought.valid - Unvalidated passthrough: Thoughts that have never been validated are passed through (not filtered out), with a warning logged to alert that unvalidated thoughts are present
- Creates cloned copies of kept thoughts via
Thought.from_thoughtto preserve immutability - Requires at least one predecessor operation (enforced by assertion)
- Does not interact with the language model, Prompter, or Parser -- it is a pure filtering operation
- Logs the number of thoughts kept for debugging and monitoring
Usage
Use the KeepValid operation after a ValidateAndImprove operation (or any operation that sets the valid flag on thoughts) to filter out thoughts that failed validation. Common scenarios include:
- After ValidateAndImprove: Remove thoughts that could not be improved to a valid state even after all retry attempts
- Quality gates: Insert KeepValid at critical points in the reasoning graph to ensure only valid thoughts proceed
- Pipeline safety: Use KeepValid before Aggregate or KeepBestN to prevent invalid thoughts from contaminating downstream operations
Note: If KeepValid receives thoughts that have never been validated, it passes them through with a warning. This is intentional to prevent silent data loss, but users should ensure that validation has been performed upstream if strict filtering is desired.
Theoretical Basis
The KeepValid operation implements boolean filtering on the thought graph, complementing the score-based filtering of KeepBestN. While KeepBestN uses quantitative scores to select the best candidates, KeepValid uses a binary valid/invalid classification.
In the GoT framework's graph structure, KeepValid acts as a gate vertex that allows only qualifying thoughts to flow to successor operations. The filtering predicate is:
keep(t) = (not validated(t)) or valid(t)
This predicate has three cases:
- validated(t) = True, valid(t) = True -- thought passes validation, kept
- validated(t) = True, valid(t) = False -- thought fails validation, discarded
- validated(t) = False -- thought never validated, kept with warning
The decision to pass through unvalidated thoughts (rather than discarding them) follows the principle of conservative filtering: in the absence of evidence that a thought is invalid, it should not be discarded. This prevents data loss in pipelines where some thoughts may bypass the validation step.
Code Reference
The Validity Filtering principle is implemented in the KeepValid class:
- Source file:
graph_of_thoughts/operations/operations.py, Lines 712-773 - Class:
KeepValid(Operation) - Operation type:
OperationType.keep_valid
Related Pages
- Implementation:Spcl_Graph_of_thoughts_KeepValid_Operation - Concrete implementation of this principle
- Principle:Spcl_Graph_of_thoughts_Validation_And_Improvement - ValidateAndImprove operation that sets the valid flag checked by KeepValid
- Principle:Spcl_Graph_of_thoughts_Best_N_Selection - Score-based filtering (complementary to boolean-based KeepValid)
- Workflow:Spcl_Graph_of_thoughts_GoT_Keyword_Counting_Pipeline - Keyword counting workflow using validation-based filtering