Back to Index
pgvectorPydanticFastAPIOpenAI

Commudle-Sense

The Problem

Community platforms rely on rigid, keyword-based search bars that completely fail on complex queries (e.g., 'Android developers near Lucknow'). Connecting an LLM directly to the database to solve this risked catastrophic data leakage and SQL injection attacks.

The Hard Constraint

We needed a 100% defense against adversarial prompt injection scenarios while securely querying over 1,900 cross-platform records using an untrusted LLM extractor.

Architecture

[User Query] │ ▼ [Guard: Llama-Guard-3] ──(Fail)──► [Reject] │ (Pass) ▼ [Extract: Qwen-2.5] │ (Strict Pydantic JSON Schema) ▼ [Validate: Type & Injection Check] │ ▼ [Permissions: RBAC Context Check] │ ▼ [Rank: pgvector Semantic Search] │ ▼ [Results to User]

Results & Caveats

The Outcome

Successfully engineered a 5-stage code-enforced pipeline. Treated the LLM purely as an untrusted JSON extractor locked by schemas. Achieved 100% defense against 31 distinct adversarial prompt injection scenarios.

Honest Caveats

The multi-stage pipeline introduces a slight latency overhead compared to a direct text-to-SQL approach, heavily dependent on the response times of the initial Llama-Guard security layer.