{"success":true,"name":"design-search-and-filter-params-as-a-contract-not-a-query-pa","description":"Adding search, filtering, or sorting options to a list API","category":"ai-brimind","path":"ai-brimind/design-search-and-filter-params-as-a-contract-not-a-query-pa/SKILL.md","file":"SKILL.md","content":"---\nname: design-search-and-filter-params-as-a-contract-not-a-query-pa\ndescription: \"Adding search, filtering, or sorting options to a list API\"\n---\n\n# Design Search and Filter Params as a Contract, Not a Query Passthrough\n\n## When to use\nYou are adding filter/sort/search query params to an endpoint, and the params are being wired straight into database queries as they arrive.\n\n## Example request\nClient can filter by any field name it sends → internal columns become public API and queries hit unindexed fields; a whitelist of filterable fields is the contract. — Sort param passed raw into the query → 'sort=;DROP…' or unindexed sorts; allowed sort keys must be enumerated, not interpolated. — Filters multiply into unindexed combinations → the database scans everything; each promised filter combination needs an index plan. — Search behavior undefined → clients guess whether it's exact, prefix, or fuzzy; the matching rule is part of the contract.\n\n## Instructions\nAct as a query-contract designer who treats every filter param as a public promise with a database cost. When adding search/filter/sort: 1) Whitelist explicitly: enumerate the exact filterable fields, allowed operators, and sortable keys — anything not listed is rejected with a clear 400, never passed through to the query layer. 2) For each promised filter and sort, check the database side: does an index support it at real data volume? A filter you can't serve efficiently is a promise you can't keep — cut it or index it. 3) Define the semantics precisely in the contract: exact vs partial match, case sensitivity, how multiple filters combine (AND/OR), and how filters interact with pagination's stable ordering. 4) Check for the project's existing query-building/filtering mechanism and reuse its param conventions so all list endpoints speak the same dialect. 5) If asked for 'filter by anything', push back with the concrete cost — flexible-everything is how databases die. Only ship once each documented filter is confirmed both validated and indexed, and explain how the whitelist protects both security and performance rather than limiting users arbitrarily.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #908\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}