home / skills / bdambrosio / cognitive_workbench / filter-structured
This skill filters a collection of dict notes by a SQL-like WHERE predicate, returning only matching entries.
npx playbooks add skill bdambrosio/cognitive_workbench --skill filter-structuredReview the files below or copy the command above to add this skill to your agents.
---
name: filter-structured
type: primitive
description: Filter Collection by field conditions (SQL WHERE)
---
# Filter-Structured
## INPUT CONTRACT
- `target`: Collection (variable or ID)
- `where`: SQL-like predicate string (e.g., `"year > 2020"`, `"score >= 0.5 AND year < 2025"`)
- `out`: Variable name
**REQUIREMENTS:**
- Collection MUST contain dict/JSON Notes
- WHERE clause uses field names (dot notation supported)
- Operators: `>`, `<`, `>=`, `<=`, `==`, `!=`, `AND`, `OR`
**NOT SUPPORTED:**
- ❌ Note (must be Collection)
- ❌ Collection of arrays (must be dict Notes)
- ❌ Text parsing (use `filter-semantic` tool for semantic filtering)
## OUTPUT
Returns Collection of Notes matching WHERE clause. Notes missing fields are excluded.
## FAILURE SEMANTICS
**Empty Collection = expected when:**
- No Notes match predicate
- Type contract violated
**Empty ≠ error** — indicates no matches, not failure.
**Actual failures:** Invalid target type, malformed WHERE clause, or missing parameters.
## REPRESENTATION INVARIANTS
- Note containing JSON array ≠ Collection
- Use `split` to convert array → Collection before filtering
## ANTI-PATTERNS
❌ `filter-structured(target=$note)` → Must be Collection
❌ `filter-structured(target=$coll_of_arrays)` → Elements must be dicts
❌ `filter-structured(target=$text_note)` → Use `filter-semantic` for semantic filtering
❌ Treating empty result as error → Empty = no matches
This skill filters a collection of JSON/dict Notes using SQL-like WHERE predicates. It returns a new collection containing only Notes that satisfy the field conditions, excluding items missing required fields. Empty collections indicate no matches, not an error.
You pass a target Collection, a SQL-like where string, and an output variable name. The skill evaluates the predicate against each Note (dict) using supported operators and logical connectors and includes only Notes that have the referenced fields. Notes missing any referenced field are excluded from results.
What happens if a Note is missing a field referenced in the WHERE clause?
Notes missing any referenced field are excluded from the result. Missing fields cause no match rather than an error.
Is semantic or text parsing supported in the WHERE clause?
No. This tool performs structured field comparisons only. For semantic or text-based filtering, use a dedicated semantic filter tool.