Skip to content

Commit eae3853

Browse files
BrentOzarclaude
andcommitted
Add error handling when @aimodel not found in @AIConfigTable
When users specify an @aimodel that doesn't exist in their @AIConfigTable, the procedures now raise an informational message naming the requested model, the config table searched, and the fallback model being used instead (either the table's DefaultModel or the hard-coded gpt-5-nano). Also widens the config table INSERT to always load the DefaultModel row, so the fallback can use it, and filters the ELSE branch to prefer the exact model match. Fixes #3839 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2dea66a commit eae3853

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

sp_BlitzCache.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,22 @@ BEGIN
917917
SELECT Id, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, AI_Parameters, Payload_Template, Timeout_Seconds, Context, DefaultModel FROM '
918918
+ CASE WHEN @AIConfigDatabaseName IS NOT NULL THEN (QUOTENAME(@AIConfigDatabaseName) + N'.') ELSE N'' END
919919
+ CASE WHEN @AIConfigSchemaName IS NOT NULL THEN (QUOTENAME(@AIConfigSchemaName) + N'.') ELSE N'' END
920-
+ QUOTENAME(@AIConfigTableName) + N' WHERE (@AIModel IS NULL AND DefaultModel = 1) OR @AIModel = AI_Model ; ';
920+
+ QUOTENAME(@AIConfigTableName) + N' WHERE DefaultModel = 1 OR @AIModel = AI_Model ; ';
921921
EXEC sp_executesql @config_sql, N'@AIModel NVARCHAR(100)', @AIModel;
922922
END;
923923

924+
IF @AIModel IS NOT NULL AND @AIConfigTable IS NOT NULL
925+
AND NOT EXISTS (SELECT 1 FROM #ai_providers WHERE AI_Model = @AIModel)
926+
BEGIN
927+
DECLARE @AIModelRequested NVARCHAR(200) = @AIModel;
928+
DECLARE @AIFallbackModel NVARCHAR(200);
929+
SELECT TOP 1 @AIFallbackModel = AI_Model FROM #ai_providers WHERE DefaultModel = 1 ORDER BY Id;
930+
IF @AIFallbackModel IS NULL SET @AIFallbackModel = N'gpt-5-nano';
931+
RAISERROR('@AIModel "%s" was not found in configuration table %s. Using "%s" instead.',
932+
10, 1, @AIModelRequested, @AIConfigTable, @AIFallbackModel) WITH NOWAIT;
933+
SET @AIModel = NULL;
934+
END;
935+
924936
IF @AIPromptConfigTable IS NOT NULL
925937
BEGIN
926938
RAISERROR(N'Reading values from AI Prompts Table', 0, 1) WITH NOWAIT;
@@ -974,6 +986,7 @@ IF @AI > 0
974986
@AITimeoutSeconds = COALESCE(Timeout_Seconds, 230),
975987
@AIContext = Context
976988
FROM #ai_providers
989+
WHERE AI_Model = @AIModel
977990
ORDER BY Id;
978991

979992
/* Check the prompts table */

sp_BlitzIndex.sql

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,10 +1031,22 @@ BEGIN
10311031
SELECT Id, AI_Model, AI_URL, AI_Database_Scoped_Credential_Name, AI_Parameters, Payload_Template, Timeout_Seconds, Context, DefaultModel FROM '
10321032
+ CASE WHEN @AIConfigDatabaseName IS NOT NULL THEN (QUOTENAME(@AIConfigDatabaseName) + N'.') ELSE N'' END
10331033
+ CASE WHEN @AIConfigSchemaName IS NOT NULL THEN (QUOTENAME(@AIConfigSchemaName) + N'.') ELSE N'' END
1034-
+ QUOTENAME(@AIConfigTableName) + N' WHERE (@AIModel IS NULL AND DefaultModel = 1) OR @AIModel = AI_Model ; ';
1034+
+ QUOTENAME(@AIConfigTableName) + N' WHERE DefaultModel = 1 OR @AIModel = AI_Model ; ';
10351035
EXEC sp_executesql @config_sql, N'@AIModel NVARCHAR(100)', @AIModel;
10361036
END;
10371037

1038+
IF @AIModel IS NOT NULL AND @AIConfigTable IS NOT NULL
1039+
AND NOT EXISTS (SELECT 1 FROM #ai_providers WHERE AI_Model = @AIModel)
1040+
BEGIN
1041+
DECLARE @AIModelRequested NVARCHAR(200) = @AIModel;
1042+
DECLARE @AIFallbackModel NVARCHAR(200);
1043+
SELECT TOP 1 @AIFallbackModel = AI_Model FROM #ai_providers WHERE DefaultModel = 1 ORDER BY Id;
1044+
IF @AIFallbackModel IS NULL SET @AIFallbackModel = N'gpt-5-nano';
1045+
RAISERROR('@AIModel "%s" was not found in configuration table %s. Using "%s" instead.',
1046+
10, 1, @AIModelRequested, @AIConfigTable, @AIFallbackModel) WITH NOWAIT;
1047+
SET @AIModel = NULL;
1048+
END;
1049+
10381050
IF @AIPromptConfigTable IS NOT NULL
10391051
BEGIN
10401052
RAISERROR(N'Reading values from AI Prompts Table', 0, 1) WITH NOWAIT;
@@ -1083,6 +1095,7 @@ IF @AI > 0
10831095
@AITimeoutSeconds = COALESCE(Timeout_Seconds, 230),
10841096
@AIContext = Context
10851097
FROM #ai_providers
1098+
WHERE AI_Model = @AIModel
10861099
ORDER BY Id;
10871100

10881101
/* Check the prompts table */

0 commit comments

Comments
 (0)