You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to: fleetdm/confidential#9884
Changes:
- Updated the prompt in the `get-llm-generated-sql` action to include a
note about using wildcard characters when generating queries that use
the LIKE operator.
- Improved error handling in the `get-llm-generated-sql` action
Copy file name to clipboardexpand all lines: website/api/controllers/query-generator/get-llm-generated-sql.js
+46-10
Original file line number
Diff line number
Diff line change
@@ -18,8 +18,9 @@ module.exports = {
18
18
description: 'A SQL query was generated'
19
19
},
20
20
21
-
errorFromOpenAi: {
22
-
description: 'The Open AI API reutrned an error.'
21
+
couldNotGenerateQueries: {
22
+
description: 'A set of queries could not be generated for a user using the provided question.',
23
+
responseType: 'badRequest'
23
24
}
24
25
},
25
26
@@ -57,17 +58,34 @@ module.exports = {
57
58
returnlighterTable;}))}
58
59
\`\`\`
59
60
60
-
Please respond in JSON, with the same data shape as the provided context, but with the array filtered to include only relevant tables.`;
61
+
Please respond in JSON, with the same data shape as the provided context, but with the array filtered to include only relevant tables.
62
+
63
+
64
+
If no queries can be generated from the provided instructions do not return the datashape above and instead return this JSON in this exact data shape:
65
+
66
+
{
67
+
"couldNotGenerateQueries": true
68
+
}`;
69
+
61
70
letfilteredTables=awaitsails.helpers.ai.prompt(schemaFiltrationPrompt,'gpt-4o-mini-2024-07-18',true,'Please only respond in valid JSON with no codefences or backticks.')
62
71
.intercept((err)=>{
72
+
sails.log.warn(`When trying to get a subset of tables to use to generate a query for a user, an error occurred. Full error: ${require('util').inspect(err,{depth: 2})}`);
63
73
if(this.req.isSocket){
64
74
// If this request was from a socket and an error occurs, broadcast an 'error' event and unsubscribe the socket from this room.
returnnewError(`When trying to get a subset of tables to use to generate a query for an Admin user, an error occurred. Full error: ${require('util').inspect(err,{depth: 2})}`);
// 2024-02-26: Testing using a system prompt with a single API request.
73
91
// let systemPrompt = `You are an AI that generates osquery SQL queries for IT admin questions. Use the following osquery schema as context:
@@ -120,11 +138,12 @@ module.exports = {
120
138
121
139
When generating the SQL:
122
140
1. Please do not use the SQL "AS" operator, nor alias tables. Always reference tables by their full name.
123
-
2. If this question is related to an application or program, consider using LIKE instead of something verbatim.
124
-
3. If this question is not possible to ask given the tables and columns available in the provided context (the osquery schema) for a particular operating system, then use empty string.
125
-
4. If this question is a "yes" or "no" question, or a "how many people" question, or a "how many hosts" question, then build the query such that a "yes" returns exactly one row and a "no" returns zero rows. In other words, if this question is about finding out which hosts match a "yes" or "no" question, then if a host does not match, do not include any rows for it.
126
-
5. Use only tables that are supported for each target platform, as documented in the provided context, considering the examples if they exist, and the available columns.
127
-
6. For each table that you use, only use columns that are documented for that table, as documented in the provided context.
141
+
2. When generating a query that uses the "LIKE" operator, you should include wildcard characters.
142
+
3. If this question is related to an application or program, consider using LIKE instead of something verbatim.
143
+
4. If this question is not possible to ask given the tables and columns available in the provided context (the osquery schema) for a particular operating system, then use empty string.
144
+
5. If this question is a "yes" or "no" question, or a "how many people" question, or a "how many hosts" question, then build the query such that a "yes" returns exactly one row and a "no" returns zero rows. In other words, if this question is about finding out which hosts match a "yes" or "no" question, then if a host does not match, do not include any rows for it.
145
+
6. Use only tables that are supported for each target platform, as documented in the provided context, considering the examples if they exist, and the available columns.
146
+
7. For each table that you use, only use columns that are documented for that table, as documented in the provided context.
128
147
129
148
Provided context:
130
149
\`\`\`
@@ -142,6 +161,13 @@ module.exports = {
142
161
"windowsCaveats": "TODO",
143
162
"linuxCaveats": "TODO",
144
163
"chromeOSCaveats": "TODO",
164
+
}
165
+
166
+
167
+
If no queries can be generated from the provided instructions do not return the datashape above and instead return this JSON in this exact data shape:
0 commit comments