Skip to content

feat(analyze): FERPA runtime guard for NLQ-generated SQL (#127)#132

Merged
William-Hill merged 2 commits into
mainfrom
fix/issue-127-ferpa-nlq-guard
May 3, 2026
Merged

feat(analyze): FERPA runtime guard for NLQ-generated SQL (#127)#132
William-Hill merged 2 commits into
mainfrom
fix/issue-127-ferpa-nlq-guard

Conversation

@William-Hill
Copy link
Copy Markdown
Collaborator

Summary

Implements #127: server-side validation that LLM-produced SQL does not project Student_GUID / student_guid (or other ferpaExcluded columns), with Vitest coverage.

Changes

  • lib/sql-inspector.ts: inspectSelectForFerpaExclusions(sql, excluded) — parses top-level SELECT list (first FROM at paren depth 0), rejects bare *, quoted/unquoted excluded identifiers in the SELECT list only (not WHERE, which is outside the extracted clause).
  • app/api/analyze/route.ts: After streaming the plan, if schemaInfo.ferpaExcluded is non-empty, run the inspector; on failure → 422 { error: "FERPA exclusion violated", column } and console.warn (no third-party logging).
  • Tests: app/api/analyze/__tests__/ferpa-exclusions.test.ts (5 required cases + empty exclusion list).
  • vitest.config.ts: include analyze tests path.
  • content/ai-transparency.ts: nlq-analyzer notes mention the runtime guard.

How to verify

cd codebenders-dashboard && npx vitest run app/api/analyze/__tests__/ferpa-exclusions.test.ts

Closes #127

Made with Cursor

William-Hill and others added 2 commits May 3, 2026 11:05
- Add lib/sql-inspector.ts: conservative SELECT-clause check (top-level FROM, * , excluded ids)
- Return 422 FERPA exclusion violated from /api/analyze when LLM SQL violates
- Tests for happy path, WHERE-only GUID, projections, alias, SELECT *, empty list
- Document runtime guard in ai-transparency nlq-analyzer notes

Co-authored-by: Cursor <cursoragent@cursor.com>
…fier)

- sql-inspector: listStart, unified selectList empty handling, .some for *
- route: ferpaBlockedResponse helper for 422 path
- tests: table-driven rejection cases

Co-authored-by: Cursor <cursoragent@cursor.com>
@William-Hill William-Hill merged commit b67f175 into main May 3, 2026
2 checks passed
@William-Hill William-Hill deleted the fix/issue-127-ferpa-nlq-guard branch May 3, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: enforce FERPA exclusions in NLQ-generated SQL (Student_GUID never appears in SELECT)

1 participant