feat: add schema anonymization mode#8
Open
wondr-wclabs wants to merge 1 commit into
Open
Conversation
6979710 to
97d333b
Compare
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.
Closes #3.
This adds a
--anonymizemode that keeps PromptQuery's local retrieval and safety model intact while avoiding sending real table and column names to LLMs.The reason I kept this as a separate
SchemaAnonymizerlayer instead of mixing it intoformat_schema()is that there are two different responsibilities here:validate_select_only()anddb.execute(), so the existing sqlglot safety guard and read-only DB session continue to operate on the real SQLImplementation notes:
table_001,table_002, ...), based on the introspected schema ordercolumn_001,column_002, ...), preserving column orderOne deliberate boundary: this anonymizes schema identifiers sent by PromptQuery, not the user's natural-language question. It also preserves PostgreSQL type strings for query quality, so a custom type name could still be visible if the database uses semantic type names. I left that out of scope because the issue calls for table/column anonymisation and because replacing type information would make generated SQL materially worse.
Tests added/updated:
run_question()sends anonymized prompts to both generator and selector paths--anonymizeValidation:
.venv/bin/pytest-> 56 passedgit diff --check-> clean