sp_BlitzCache: Fix ai_prompt returning nulls when @AI > 0#3856
Closed
sp_BlitzCache: Fix ai_prompt returning nulls when @AI > 0#3856
Conversation
- Remove QueryPlan IS NOT NULL filter from prompt-building UPDATE - Add explicit messages when query text/plan cannot be retrieved - Override ai_prompt with simple message when both are NULL - Update AI cursor to process rows with at least one of plan/text - Update output SELECT to skip system prompt for both-null case - Update constitution cursor to include text-only rows Co-authored-by: BrentOzar <245462+BrentOzar@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [ISSUE-123] Fix nulls in sp_BlitzCache ai_advice and ai_prompt
sp_BlitzCache: Fix ai_prompt returning nulls when @AI > 0
Mar 16, 2026
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.
ai_promptcould be NULL when@AI = 1or@AI = 2because the prompt-building UPDATE filtered out rows whereQueryPlan IS NULL, and the output SELECT would concatenate@AISystemPrompt + NULL→ NULL.Changes
QueryPlan IS NOT NULLgate from prompt builder — prompts are now built for all rows when@AI > 0ISNULL(..., N'N/A')replaced withCASE WHEN ... IS NULL THEN N'(Query text/plan could not be retrieved.)'for bothQueryTextandQueryPlanQueryTextandQueryPlanare NULL,ai_promptis set to a simple message with no metrics or system prompt:AND QueryPlan IS NOT NULLtoAND (QueryPlan IS NOT NULL OR QueryText IS NOT NULL)so API calls still fire when at least one artifact exists[AI Prompt]columns now skip prepending@AISystemPromptfor the both-null fallback messageQueryTextis availableOriginal prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.