-
Notifications
You must be signed in to change notification settings - Fork 7
Database Debug Guide
Nathan Smith edited this page Nov 15, 2025
·
1 revision
Enhanced AI Chat answers data questions by routing through OpenAIAgent.HandleDatabaseQueryAsync. Use this playbook whenever a question like "How many renewals are pending for Acme?" fails.
Update src/Quickfire.Blazor/appsettings.Development.json so the agent logs everything:
{
"Logging": {
"LogLevel": {
"Surefire.Domain.Agents.Services.OpenAIAgent": "Debug",
"Microsoft.EntityFrameworkCore.Database.Command": "Information"
}
}
}Then restart dotnet watch run. All SQL-agent logs use the [DBQuery] prefix.
-
Semantic search –
PerformSemanticSearchAsyncqueries Qdrant (OpenAIEmbeddingService+QdrantVectorStore). Logs:[DBQuery] Starting semantic search...,[DBQuery] Enhanced input with .... -
Prompt creation –
CreateSqlGenerationPromptmerges the user question, semantic matches, and schema docs loaded fromwwwroot/schema/*.sql(LoadDatabaseSchema). -
LLM call – Semantic Kernel
IChatCompletionService(gpt-4.1) returns JSON (SQL, parameters, explanation). Logged as[DBQuery] Raw SQL Generation Response. -
Validation –
ValidateSQLblocks dangerous commands, enforces upper limits, and logs[DBQuery] SQL Validation - IsValid .... -
Execution – The validated SQL runs via EF Core on an open connection. Timing + row count logged as
[DBQuery] Query executed successfully with {ResultCount} rows in {Elapsed}. -
Formatting –
ResponseFormatterrenders narrative + table HTML. Suggestions list is auto-generated for follow-up questions.
| Problem | What to inspect |
|---|---|
| Semantic search misses entity | Ensure embeddings are up to date by running EmbeddingLoaderService (Profile → System Settings) and confirm Qdrant is reachable (QDRANT_BASE_URL) |
| SQL generation fails | Look at [DBQuery] Raw SQL Generation Response – often the JSON is malformed when schema docs are stale. Check wwwroot/schema contents and rerun the extractor script if needed. |
| Validation rejects query | The log includes exact errors (keywords, multiple statements, missing FROM). Refine prompts or teach the model to auto-add TOP (25) to heavy queries. |
| Execution exception | EF logs include the SQL + parameters. Verify column names (maybe a migration renamed a column), or update indexes if timeouts occur. |
| No results | Inspect the generated SQL and consider adding more filters or a different semantic match. [DBQuery] Enhanced input... shows which entities were injected. |
-
/agents/enhanced/chat?debug=trueshows inline intent badges and the final SQL snippet rendered in the UI. -
wwwroot/schemaholds.sqlfiles withLLM_SearchHintsextended properties; keep them updated to teach the model which fields matter. -
/ref/schema/extractor.jsondocuments the canonical schema. Update it when you add tables or rename columns.
[DBQuery] Starting semantic search for: ...[DBQuery] Enhanced input with ... semantic matches[DBQuery] Raw SQL Generation Response: ...[DBQuery] Parsed SQL Success: True/False[DBQuery] SQL Validation - IsValid: ...[DBQuery] Query executed successfully with X rows in Y ms
Following these steps will show you exactly where a database question fell down—entity resolution, prompt, validation, or SQL execution—and what to fix next.
Quickfire Wiki • Generated from Qf-Docs/wiki • Last updated: 2025-11-14.
See the main repo for README + issues.
- Home
- Getting Started
- System Architecture
- Release Notes
- Features
- Agents & AI
- Reference
- Guides
- Integrations
- Archive