Skip to content

Commit f107107

Browse files
committed
Simplify no match logic for ai choose rule
1 parent 8222508 commit f107107

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

apps/web/utils/ai/choose-rule/ai-choose-rule.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Braintrust } from "@/utils/braintrust";
88

99
const logger = createScopedLogger("ai-choose-rule");
1010

11-
const braintrust = new Braintrust("choose-rule-1");
11+
const braintrust = new Braintrust("choose-rule-2");
1212

1313
type GetAiResponseOptions = {
1414
email: EmailForLLM;
@@ -29,14 +29,13 @@ async function getAiResponse(options: GetAiResponseOptions) {
2929
<priority>
3030
1. Match the email to a SPECIFIC user-defined rule that addresses the email's exact content or purpose.
3131
2. If the email doesn't match any specific rule but the user has a catch-all rule (like "emails that don't match other criteria"), use that catch-all rule.
32-
3. Only use rule system fallback if no user-defined rule can reasonably apply.
32+
3. Only set "noMatchFound" to true if no user-defined rule can reasonably apply.
3333
</priority>
3434
3535
<guidelines>
3636
- If a rule says to exclude certain types of emails, DO NOT select that rule for those excluded emails.
3737
- When multiple rules match, choose the more specific one that best matches the email's content.
3838
- Rules about requiring replies should be prioritized when the email clearly needs a response.
39-
- The system fallback rule should ONLY be selected when there is absolutely no user-defined rule that could apply.
4039
</guidelines>
4140
</instructions>
4241
@@ -51,13 +50,6 @@ ${rules
5150
.join("\n")}
5251
</user_rules>
5352
54-
<system_fallback>
55-
<name>System fallback</name>
56-
<instructions>
57-
The system fallback rule should ONLY be selected when there is absolutely no user-defined rule that could apply.
58-
</instructions>
59-
</system_fallback>
60-
6153
${
6254
user.about
6355
? `<user_info>
@@ -73,6 +65,7 @@ ${
7365
Respond with a JSON object with the following fields:
7466
"reason" - the reason you chose that rule. Keep it concise.
7567
"ruleName" - the exact name of the rule you want to apply
68+
"noMatchFound" - true if no match was found, false otherwise
7669
</outputFormat>`;
7770

7871
const prompt = `Select a rule to apply to this email that was sent to me:
@@ -106,6 +99,7 @@ ${emailSection}
10699
schema: z.object({
107100
reason: z.string(),
108101
ruleName: z.string(),
102+
noMatchFound: z.boolean().optional(),
109103
}),
110104
userEmail: user.email || "",
111105
usageLabel: "Choose rule",
@@ -144,6 +138,9 @@ export async function aiChooseRule<
144138
user,
145139
});
146140

141+
if (aiResponse.noMatchFound)
142+
return { rule: undefined, reason: "No match found" };
143+
147144
const selectedRule = aiResponse.ruleName
148145
? rules.find(
149146
(rule) => rule.name.toLowerCase() === aiResponse.ruleName.toLowerCase(),

0 commit comments

Comments
 (0)