Skip to content

Commit e18e0f3

Browse files
MaxGhenisclaude
andcommitted
Fix currency symbol display in AI explainer for different countries
- Add country-specific currency symbols (£ for UK, $ for US/CA, ₪ for IL, ₦ for NG) - Move prompt template to a method that selects appropriate currency based on country_id - Fixes issue where UK explanations incorrectly displayed $ instead of £ 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 4fffc99 commit e18e0f3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

policyengine_api/services/tracer_analysis_service.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ def execute_analysis(
5151
print(f"Error parsing tracer output: {str(e)}")
5252
raise e
5353

54+
# Get the appropriate prompt template based on country
55+
prompt_template = self._get_prompt_template(country_id)
56+
5457
# Add the parsed tracer output to the prompt
55-
prompt = self.prompt_template.format(
58+
prompt = prompt_template.format(
5659
variable=variable, tracer_segment=tracer_segment
5760
)
5861

@@ -135,7 +138,24 @@ def _parse_tracer_output(self, tracer_output, target_variable):
135138

136139
return result
137140

138-
prompt_template = f"""{anthropic.HUMAN_PROMPT} You are an AI assistant explaining policy calculations.
141+
def _get_prompt_template(self, country_id: str) -> str:
142+
"""Get the appropriate prompt template with correct currency symbol based on country."""
143+
144+
# Determine currency instruction based on country
145+
currency_instructions = {
146+
"uk": "The response will be rendered as markdown, so preface £ with \\.",
147+
"us": "The response will be rendered as markdown, so preface $ with \\.",
148+
"ca": "The response will be rendered as markdown, so preface $ with \\.",
149+
"il": "The response will be rendered as markdown, so preface ₪ with \\.",
150+
"ng": "The response will be rendered as markdown, so preface ₦ with \\.",
151+
}
152+
153+
currency_note = currency_instructions.get(
154+
country_id,
155+
"The response will be rendered as markdown."
156+
)
157+
158+
return f"""{anthropic.HUMAN_PROMPT} You are an AI assistant explaining policy calculations.
139159
The user has run a simulation for the variable '{{variable}}'.
140160
Here's the tracer output:
141161
{{tracer_segment}}
@@ -146,4 +166,4 @@ def _parse_tracer_output(self, tracer_output, target_variable):
146166
3. Mention any key thresholds or rules that affected the calculation.
147167
4. If relevant, suggest how changes in input might affect this result.
148168
149-
Provide only factual explanations of the policy mechanics. Do not include commentary, opinions, quotes, or phrases like "Certainly!" or "Here's an explanation." The response will be rendered as markdown, so preface $ with \\."""
169+
Provide only factual explanations of the policy mechanics. Do not include commentary, opinions, quotes, or phrases like "Certainly!" or "Here's an explanation." {currency_note}"""

0 commit comments

Comments
 (0)