feat(analyze): FERPA runtime guard for NLQ-generated SQL (#127)#132
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements #127: server-side validation that LLM-produced SQL does not project
Student_GUID/student_guid(or otherferpaExcludedcolumns), with Vitest coverage.Changes
lib/sql-inspector.ts:inspectSelectForFerpaExclusions(sql, excluded)— parses top-level SELECT list (firstFROMat paren depth 0), rejects bare*, quoted/unquoted excluded identifiers in the SELECT list only (notWHERE, which is outside the extracted clause).app/api/analyze/route.ts: After streaming the plan, ifschemaInfo.ferpaExcludedis non-empty, run the inspector; on failure → 422{ error: "FERPA exclusion violated", column }andconsole.warn(no third-party logging).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-analyzernotesmention the runtime guard.How to verify
Closes #127
Made with Cursor