Skip to content

feat: wire prompt-injection defenses into LLM tools (Item 10) - #69

Merged
mingjerli merged 6 commits into
mainfrom
feat/wire-prompt-sanitization
Jul 22, 2026
Merged

feat: wire prompt-injection defenses into LLM tools (Item 10)#69
mingjerli merged 6 commits into
mainfrom
feat/wire-prompt-sanitization

Conversation

@mingjerli

Copy link
Copy Markdown
Owner

Stacked on the Item 7 PR (#68). Applies the four prompt-injection defense layers at the LLM call sites, wiring in the existing (previously dead) prompt_sanitization.py:

  • L1 content delimiting<data> (descriptions), <schema>/<question> (SQL gen), <sql> (explain), each with a do-not-follow directive.
  • L2 input sanitization — user question + all schema/context blobs escaped (non-truncating max_length for large schema); SQL expressions via sanitize_sql_for_prompt.
  • L3 structured messages — new LLMTool.call_llm_structured (system/user role split); used by the description and explain paths.
  • L4 output validation_validate_description_output → existing rule-based fallback; generated SQL blocked on destructive ops, passed through (with warning) when sqlglot can't parse.

All new tests exercise public entry points and are pinned so they fail if a defense is removed. Full suite: 1554 passed / 70 skipped / 2 xfailed.

A whole-branch review flagged two same-class holes on entry points outside this plan's scopefrom_dbt_models (unvalidated .sql reads) and table.py table-level descriptions (unsanitized). Neither is overclaimed in the CHANGELOG; tracking separately.

Design: plans/clgraph-items-7-10-wiring-design.md

@mingjerli
mingjerli force-pushed the feat/wire-prompt-sanitization branch from a610938 to 0c3d97f Compare July 22, 2026 12:45
@mingjerli
mingjerli changed the base branch from feat/wire-path-validation to main July 22, 2026 12:45
@mingjerli
mingjerli merged commit 831e77e into main Jul 22, 2026
9 checks passed
@mingjerli
mingjerli deleted the feat/wire-prompt-sanitization branch July 22, 2026 15:21
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.

1 participant