Transform vague financial goals like “retire in 15 years” into structured targets using OpenAI with template fallbacks
Drift’s goal parser converts natural language descriptions into structured financial targets with amounts and timelines, enabling users to express goals in plain English rather than precise dollar amounts.
From /home/daytona/workspace/source/simulation/goal_parser.py:66-73:
class ParsedGoal(BaseModel): goal_type: str # retirement, house, emergency_fund, etc. target_amount: float # Dollar amount needed timeline_months: int # How many months to achieve it description: str # Human-readable summary confidence: float # 0-1 confidence score source: str = "ai" # ai | template | fallback
User: "I want to retire in 15 years"Context: $6,500/month income
AI Prompt (excerpt from /home/daytona/workspace/source/simulation/goal_parser.py:144-178):
prompt = f"""You are a financial advisor. Parse the following savings goal and extract:1. Type of goal (retirement, house, emergency_fund, vacation, college, car, custom)2. Target amount in USD3. Timeline in months4. Whether the goal description contains enough information to parseUser context:- Monthly income: $6,500- Risk tolerance: medium- Goal description: "I want to retire in 15 years"Respond as JSON:{{ "goal_type": "retirement", "target_amount": 1950000, // 25x annual salary = $6500 * 12 * 25 "timeline_months": 180, "description": "Retirement in 15 years (25x annual salary)", "confidence": 0.9, "needs_clarification": false, "clarifying_questions": []}}"""
Output:
ParsedGoal( goal_type="retirement", target_amount=1_950_000, timeline_months=180, description="Retirement in 15 years (25x annual salary)", confidence=0.9, source="ai")
ParsedGoal( goal_type="house", target_amount=100_000, # 20% down on $500k house timeline_months=60, description="House down payment", confidence=0.75, source="ai")
{ "goal_type": "car", "target_amount": null, "timeline_months": null, "description": "Purchase a corvette", "confidence": 0.2, "needs_clarification": true, "clarifying_questions": [ "A corvette typically costs $50,000-$100,000+. Did you mean $300 or $30,000?", "When do you want to buy the corvette?" ]}
From /home/daytona/workspace/source/simulation/goal_parser.py:219-235:
From /home/daytona/workspace/source/simulation/goal_parser.py:263-301:
def parse_goal_with_templates( goal_text: str, monthly_income: float, current_age: int = 30) -> ParsedGoal: """Fall back to template matching if OpenAI is unavailable.""" goal_lower = goal_text.lower() # Handle common synonym: "retire" should map to "retirement" if "retire" in goal_lower and "retirement" not in goal_lower: goal_lower += " retirement" for goal_type, template in GOAL_TEMPLATES.items(): if goal_type in goal_lower: target = template['multiplier'](monthly_income) timeline = template['default_years'] * 12 # Extract years if specified (e.g., "in 10 years") years_match = re.search(r'(\d+)\s*years?', goal_lower) if years_match: timeline = int(years_match.group(1)) * 12 goal = ParsedGoal( goal_type=goal_type, target_amount=round(target, 2), timeline_months=timeline, description=template['description'], confidence=0.7, source="template" ) return _validate_goal_output(goal, monthly_income)