- Daily deal health checks
- Pipeline review automation
- Identify at-risk deals
- Generate AI-powered next steps
- Scale deal analysis across entire pipeline
Overview
This workflow combines HubSpot data with AI analysis to automatically assess deal health. For each deal in your target stage, it:- Searches for deals in a specific stage
- Loops through each deal
- Gets timeline events for historical context
- Sends deal data + timeline to AI for analysis
- Updates the deal with AI-generated insights
What You’ll Need
HubSpot Setup
Custom Properties (create these in HubSpot → Settings → Properties → Deals):ai_health_score
(Number) - Stores 1-10 health ratingai_risks
(Multi-line text) - Stores identified risksai_next_steps
(Multi-line text) - Stores recommended actionsai_close_likelihood
(Single-line text) - Stores probability assessment
- Read Deals
- Write Deals
- Read Timeline Events
Agent.AI Setup
Actions needed:- Search HubSpot (V2)
- For Loop
- Get Timeline Events (V2)
- Invoke LLM (or Generate Content)
- Update HubSpot Object (V2)
- End Loop
- OpenAI, Anthropic, or other LLM provider configured
Step-by-Step Setup
Step 1: Add a Trigger
Choose how to run this workflow: Option A: Scheduled (Recommended)- Trigger: Schedule
- Frequency: Daily at 9:00 AM
- Use for: Regular pipeline health checks
- Trigger: Manual
- Use for: On-demand analysis
Step 2: Search for Target Deals
Add action: Search HubSpot (V2) Configuration:- Object Type: Deals
- Search Filters: Click ”+ Add Property”
- Property: Deal Stage
- Operator: Equals
- Value: “presentationscheduled” (or your target stage)
- Retrieve Properties: Click ”+ Add Property” and select:
dealname
dealstage
amount
closedate
hs_object_id
pipeline
hubspot_owner_id
- Sort:
-createdate
(newest first) - Limit: 50 (adjust based on your needs)
- Output Variable:
target_deals
Step 3: Start Loop
Add action: For Loop Configuration:- Loop through: Click
{}
→ selecttarget_deals
- Current item variable:
current_deal
Step 4: Get Timeline Events
Add action: Get Timeline Events (V2) Configuration:- Object Type: Deals
- Object ID: Click
{}
→current_deal
→hs_object_id
- Event Type Filter: Leave blank (get all events)
- Output Variable:
deal_timeline
Step 5: AI Analysis
Add action: Invoke LLM (or Generate Content) Configuration:- Prompt:
- Model: gpt-4 (or your preferred LLM)
- Output Variable:
deal_insights
Step 6: Update Deal with Insights
Add action: Update HubSpot Object (V2) Configuration:- Object Type: Deals
- Identify by: Lookup by Object ID
- Identifier: Click
{}
→current_deal
→hs_object_id
- Update Properties: Click ”+ Add Property” and select your custom properties:
ai_health_score
: Click{}
→deal_insights
→health_score
ai_risks
: Click{}
→deal_insights
→risks
ai_next_steps
: Click{}
→deal_insights
→next_steps
ai_close_likelihood
: Click{}
→deal_insights
→close_likelihood
- Output Variable:
updated_deal
Step 7: Close the Loop
Add action: End Loop What this does: Marks the end of the loop. Workflow jumps back to Step 3 and processes the next deal.Step 8 (Optional): Send Summary
Add action: Send Email (after the loop) Configuration:- To: Your email or sales team email
- Subject: “Deal Analysis Complete”
- Body: “Analyzed and updated insights for all deals in Presentation Scheduled stage.”
How It Works
Execution flow:- Search finds 50 deals in “Presentation Scheduled” stage → saves to
target_deals
- For Loop starts with first deal →
current_deal
= Deal #1 - Get Timeline Events retrieves history for Deal #1 → saves to
deal_timeline
- Invoke LLM analyzes Deal #1 + timeline → saves insights to
deal_insights
- Update writes insights back to Deal #1 in HubSpot
- End Loop → Jump back to step 2,
current_deal
= Deal #2 - Repeat until all 50 deals are analyzed
- Send Email (optional) notifies team
Example Output
What the AI Generates
For a deal named “Acme Corp - Enterprise License”:What Appears in HubSpot
In the deal record, you’ll see:- AI Health Score: 7
- AI Risks: “Customer has not responded to follow-up in 5 days…”
- AI Next Steps: “1. Send follow-up email… 2. Offer integration consultation…”
- AI Close Likelihood: “Medium-High (65%)”
Customization Ideas
Different Target Stages
Change which stage to analyze:- Search Filter Value: Change from “presentationscheduled” to:
- “qualifiedtobuy” - Recently qualified deals
- “decisionmakerboughtin” - Deals nearing close
- “contractsent” - Contracts waiting for signature
Multiple Stages
Run separate workflows for different stages, or add an If Condition inside the loop to handle different stages differently.Different AI Focus
Customize the LLM prompt for different analysis types: For early-stage deals:Add Filters
Only analyze deals meeting certain criteria: After Get Timeline Events, add If Condition:- Condition: Check if timeline has any events in last 7 days
- If no recent activity → Tag as “stalled”
- If has activity → Run AI analysis
Segment by Owner
After Search, add another loop:- Group deals by
hubspot_owner_id
- Send each owner a summary of their deals
Troubleshooting
No Deals Found
Search returns empty array Causes:- No deals in that stage
- Wrong stage name (check exact value in HubSpot)
- Missing permissions
- Check HubSpot - do deals exist in that stage?
- Get exact stage value: Go to HubSpot → Deal → Check “Deal Stage” property
- Verify “Read Deals” permission
AI Insights Not Formatted Correctly
Deal properties contain raw JSON or malformed text Causes:- LLM didn’t follow JSON format instruction
- Template variable rendering issue
- Make prompt more explicit: “Return ONLY valid JSON, nothing else”
- Test with a single deal first
- Try different LLM model (GPT-4 better at structured output than GPT-3.5)
- Parse JSON in a Set Variable action before updating
Custom Properties Not Found
Error: “Property ‘ai_health_score’ does not exist” Causes:- Custom properties not created in HubSpot
- Properties created but not for Deals object
- Go to HubSpot → Settings → Properties → Deals
- Create custom properties:
ai_health_score
(Number, 0-10)ai_risks
(Multi-line text)ai_next_steps
(Multi-line text)ai_close_likelihood
(Single-line text)
- Save and try again
Timeline Too Long
LLM times out or returns incomplete response Causes:- Timeline has hundreds of events
- Exceeding token limit
- Add result limit to Get Timeline Events action
- Filter by date range (last 30 days)
- Filter by event type (only important events)
- Use LLM with larger context window
Loop Takes Too Long
Workflow times out Causes:- Too many deals (1000+)
- LLM calls are slow
- Reduce search limit to 50-100 deals
- Run multiple smaller workflows instead of one large one
- Filter deals by date (only deals from last 30 days)
Tips & Best Practices
✅ Do:- Start with small search limit (10-20 deals) to test
- Review AI-generated insights for a few deals before scaling
- Adjust prompt based on what your team actually needs
- Create custom properties in HubSpot before running workflow
- Use scheduled trigger for daily automated analysis
- Monitor execution logs to see how long each deal takes
- Analyze thousands of deals at once (splits into batches)
- Forget to create custom properties in HubSpot first
- Use vague prompts (be specific about what you want)
- Skip testing with a few deals first
- Analyze the same stage multiple times a day (redundant)
- LLM calls cost money - monitor usage
- Use cheaper models (GPT-3.5) for simple analysis
- Limit timeline events to reduce tokens
- Only analyze deals that changed recently (add date filter)
Related Resources
Actions used: Related workflows:- HubSpot Contact Enrichment - Similar pattern for contacts
- HubSpot Customer Onboarding - Multi-stage workflow example
Last Updated: 2025-10-01