Skip to content

Commit e7e8826

Browse files
adjusted prompt to reduce halucinations: nested filter/context calls and putting filter args in quotation marks
1 parent 5d4ff64 commit e7e8826

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

src/dbally/iql_generator/prompt.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,16 @@ def __init__(
7676
"It is VERY IMPORTANT not to use methods other than those listed above.\n"
7777
"Finally, if a called function argument value is not directly specified in the query but instead requires "
7878
"some additional execution context, than substitute that argument value with: AskerContext().\n"
79-
'The typical input phrase suggesting that the additional execution context need to be referenced contains words like: "I", "my", "mine", "current", "the" etc..\n'
79+
"The typical input phrase suggesting that the additional execution context need to be referenced \n"
80+
'contains words like: "I", "my", "mine", "current", "the" etc..\n'
8081
'For example: "my position name", "my company valuation", "current day", "the ongoing project".\n'
8182
"In that case, the part of the output will look like this:\n"
8283
"filter4(AskerContext())\n"
84+
"Outside this situation DO NOT combine filters like this:\n"
85+
"filter4(filter2())\n"
86+
"And NEVER quote the filter argument unless you're sure it represents the string/literal datatype, \n"
87+
"Especially do not quote AskerContext() calls like this:\n"
88+
"filter2('AskerContext()')\n"
8389
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
8490
"This is CRUCIAL, otherwise the system will crash. "
8591
),

tests/unit/test_iql_format.py

+26-12
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ async def test_iql_prompt_format_default() -> None:
2222
"DO NOT INCLUDE arguments names in your response. Only the values.\n"
2323
"You MUST use only these methods:\n"
2424
"\n\n"
25-
"It is VERY IMPORTANT not to use methods other than those listed above."
26-
"Finally, if a called function argument value is not directly specified in the query but instead requires some additional execution context, than substitute that argument value with: AskerContext()."
27-
'The typical input phrase suggesting that the additional execution context need to be referenced contains words like: "I", "my", "mine", "current", "the" etc..'
28-
'For example: "my position name", "my company valuation", "current day", "the ongoing project".'
29-
"In that case, the part of the output will look like this:"
30-
"filter4(AskerContext())"
25+
"It is VERY IMPORTANT not to use methods other than those listed above.\n"
26+
"Finally, if a called function argument value is not directly specified in the query but instead requires "
27+
"some additional execution context, than substitute that argument value with: AskerContext().\n"
28+
"The typical input phrase suggesting that the additional execution context need to be referenced \n"
29+
'contains words like: "I", "my", "mine", "current", "the" etc..\n'
30+
'For example: "my position name", "my company valuation", "current day", "the ongoing project".\n'
31+
"In that case, the part of the output will look like this:\n"
32+
"filter4(AskerContext())\n"
33+
"Outside this situation DO NOT combine filters like this:\n"
34+
"filter4(filter2())\n"
35+
"And NEVER quote the filter argument unless you're sure it represents the string/literal datatype, \n"
36+
"Especially do not quote AskerContext() calls like this:\n"
37+
"filter2('AskerContext()')\n"
3138
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
3239
"This is CRUCIAL, otherwise the system will crash. ",
3340
"is_example": False,
@@ -57,12 +64,19 @@ async def test_iql_prompt_format_few_shots_injected() -> None:
5764
"DO NOT INCLUDE arguments names in your response. Only the values.\n"
5865
"You MUST use only these methods:\n"
5966
"\n\n"
60-
"It is VERY IMPORTANT not to use methods other than those listed above."
61-
"Finally, if a called function argument value is not directly specified in the query but instead requires some additional execution context, than substitute that argument value with: AskerContext()."
62-
'The typical input phrase suggesting that the additional execution context need to be referenced contains words like: "I", "my", "mine", "current", "the" etc..'
63-
'For example: "my position name", "my company valuation", "current day", "the ongoing project".'
64-
"In that case, the part of the output will look like this:"
65-
"filter4(AskerContext())"
67+
"It is VERY IMPORTANT not to use methods other than those listed above.\n"
68+
"Finally, if a called function argument value is not directly specified in the query but instead requires "
69+
"some additional execution context, than substitute that argument value with: AskerContext().\n"
70+
"The typical input phrase suggesting that the additional execution context need to be referenced \n"
71+
'contains words like: "I", "my", "mine", "current", "the" etc..\n'
72+
'For example: "my position name", "my company valuation", "current day", "the ongoing project".\n'
73+
"In that case, the part of the output will look like this:\n"
74+
"filter4(AskerContext())\n"
75+
"Outside this situation DO NOT combine filters like this:\n"
76+
"filter4(filter2())\n"
77+
"And NEVER quote the filter argument unless you're sure it represents the string/literal datatype, \n"
78+
"Especially do not quote AskerContext() calls like this:\n"
79+
"filter2('AskerContext()')\n"
6680
"""If you DON'T KNOW HOW TO ANSWER DON'T SAY \"\", SAY: `UNSUPPORTED QUERY` INSTEAD! """
6781
"This is CRUCIAL, otherwise the system will crash. ",
6882
"is_example": False,

0 commit comments

Comments
 (0)