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
"""Remove format hints from a parameter description.
35
+
36
+
Strips patterns such as ``(YYYY-MM-DD)``, ``(ISO 8601)``,
37
+
``(2-letter code)``, ``(HH:MM:SS)``, and trailing
38
+
``in the format YYYY-MM-DD`` phrases. The sanitised description is used
39
+
only for LLM question generation; the original description (with format
40
+
hints intact) is still used for extraction context.
41
+
"""
42
+
forpatternin_FORMAT_HINT_PATTERNS:
43
+
description=pattern.sub("", description)
44
+
returndescription.strip()
45
+
18
46
19
47
classParamExtractionResult(TypedDict):
20
48
"""Return contract for ParamExtractionModule.forward()."""
@@ -34,6 +62,9 @@ class ParamExtractionSignature(dspy.Signature):
34
62
short follow-up messages ("I'm not sure", "2026-01-01") are unreliable indicators.
35
63
Always use session_language.
36
64
65
+
If custom_instructions is non-empty, follow those rules with HIGHEST PRIORITY —
66
+
they override defaults (e.g. language policy, tone) for the clarifying_question output.
67
+
37
68
Extraction rules:
38
69
- Extract values for ALL parameters listed in params_schema that appear in user_message
39
70
or conversation_history, regardless of whether they are already in already_collected
@@ -42,6 +73,12 @@ class ParamExtractionSignature(dspy.Signature):
42
73
- Only skip extraction for a param if the user has NOT mentioned it at all in this turn
43
74
- Validate types: dates must be ISO 8601 (YYYY-MM-DD), integers must be whole numbers,
44
75
numbers must be numeric, booleans must be true or false
76
+
- SINGLE-VALUE ASSIGNMENT RULE: When the user's message contains exactly ONE value of a
77
+
given type (e.g. one date) and MULTIPLE required parameters of the same type are still
78
+
missing (e.g. both startDate and endDate are missing), assign that single value to the
79
+
FIRST such missing required parameter in the order they appear in params_schema — never
80
+
to a later one. For example, if startDate appears before endDate in params_schema and
81
+
both are missing, a lone date like "2026-04-01" must be assigned to startDate, not endDate.
45
82
46
83
missing_required rules:
47
84
- List every required parameter (required=true in schema) whose value is absent
@@ -59,6 +96,11 @@ class ParamExtractionSignature(dspy.Signature):
59
96
- Use each missing parameter's description field to phrase the question naturally
60
97
(e.g., "Which country and date would you like to use?" not "Provide countryIsoCode and startDate")
61
98
- Never expose raw parameter names (camelCase identifiers) to the user
99
+
- NEVER include format requirements, expected formats, format examples, or
100
+
structural hints (such as "YYYY-MM-DD", "ISO 8601", "2-letter code",
101
+
"in the format...") in the question — only ask WHAT information is needed,
102
+
not HOW it should be formatted. The system handles format conversion
103
+
internally from any natural-language input the user provides.
62
104
"""
63
105
64
106
user_message: str=dspy.InputField(
@@ -85,6 +127,14 @@ class ParamExtractionSignature(dspy.Signature):
85
127
"still extract the new value — corrections are allowed."
86
128
)
87
129
)
130
+
custom_instructions: str=dspy.InputField(
131
+
desc=(
132
+
"Optional system-level instructions configured by the organisation "
133
+
"(e.g. 'Always respond in Estonian', 'Use formal tone'). "
134
+
"Empty string when no custom config is active. "
135
+
"When non-empty, follow these rules with highest priority for the clarifying_question."
136
+
)
137
+
)
88
138
89
139
extracted_params: str=dspy.OutputField(
90
140
desc='Valid JSON object of newly extracted parameters only: {"param_name": value}. Empty object {} if nothing new found.'
@@ -93,17 +143,29 @@ class ParamExtractionSignature(dspy.Signature):
93
143
desc='Valid JSON array of required parameter names still missing after extraction: ["param1", "param2"]. Empty array [] if all required params are satisfied.'
94
144
)
95
145
clarifying_question: str=dspy.OutputField(
96
-
desc='A single natural-language question that asks for ALL missing parameters at once, or the literal string "none" if all required params are collected.'
146
+
desc=(
147
+
"A single natural-language question that asks for ALL missing parameters "
148
+
'at once, or the literal string "none" if all required params are collected. '
149
+
'Never include format instructions or examples (e.g. "YYYY-MM-DD", '
150
+
'"ISO 8601", "2-letter code") — only ask what information is needed.'
151
+
)
97
152
)
98
153
99
154
100
155
classParamExtractionModule(dspy.Module):
101
156
"""DSPy Module for API parameter extraction from natural language."""
102
157
103
-
def__init__(self) ->None:
104
-
"""Initialize param extraction module with Predict (direct prediction)."""
0 commit comments