May 31, 2023

How to Generate Personalized Emails from your Snowflake CDP with ChatGPT, Snowpark, & Hightouch

By Peter Hansen

People are using ChatGPT for all sorts of things, from brainstorming ideas for vacations, writing & debugging code, to writing or proofreading college application essays. Your sales and marketing teams have probably already played around with using ChatGPT to communicate with customers. 

Simply interacting with the ChatGPT website isn’t going to scale to write that marketing content back to your data platform and CRM. 

In this blog, we will demonstrate how you could use your modern data stack and start generating personalized emails at scale.

Example Architecture

This example is based on using the Snowflake Data Cloud as your customer data platform (CDP). This example assumes an architecture with your CRM, like Salesforce or HubSpot, as the source of your incoming sales leads and customer data.

This data is being ingested into the Snowflake Data Cloud using Fivetran, and the data engineering has been done leveraging dbt

At this point, you are ready to prompt ChatGPT through the OpenAI API.

This will be done with a Streamlit application connected to the Snowflake tables using Snowpark. After the responses come back from ChatGPT, they are stored in a Snowflake table. Then, Hightouch surfaces that data back in our CRM, where the sales team can use it.

Streamlit Application

Now let’s look at the Streamlit application in this example. Let’s say we work for Extraordinary Events, an event planning company. We want to use ChatGPT to write custom emails to our customers. The emails can be customized based on unique customer information. We have two email campaigns to select from, one for returning customers and one for new customers.

The application queries our contact database for those sales leads that match the chosen campaign. Then, a prewritten prompt is shown to the user, instructing ChatGPT on what kind of email to write.

The art of Prompt Engineering to create effective input to ChatGPT is the most important step that determines the quality of the emails that will be generated. 

This specific prompt has a section that describes our business. We give ChatGPT a role to play: “You are writing emails…,” and then a series of instructions on how to complete the task.

The prompt can be tweaked by the user for specific purposes. For example, you might specify a signature or suggest a 15-minute meeting later this week. 

Then, you can select a specific contact from the drop-down list and ask ChatGPT to generate an email. The information about the contact is provided to ChatGPT as a part of the prompt.

If you are satisfied with the style and content of the email, you could submit all the contacts that are a part of the campaign and generate all the emails at once.

Once the emails are generated, they are saved in the Snowflake environment. I created a view that exposes the latest generated email for each contact.
Hightouch has been set up to sync the data in the Snowflake view with the corresponding fields in HubSpot. Now, your CRM is ready to send out customized emails generated by ChatGPT.


We hope that this blog helps you understand how easy it is for AI to be integrated into your CDP and how it can be used to create more engaging, interesting content.

At phData, we believe that every organization has the ability to integrate AI into its processes, and we’re excited to participate in the AI revolution. If this is something you’re interested in, phData is offering a free workshop to help explore the potential of generative AI within the modern enterprise.

In a 90-minute session, your leaders can sit down with one of our Principal Data & AI Architects to start turning ideas into a plan of action. 

Data Coach is our premium analytics training program with one-on-one coaching from renowned experts.

Accelerate and automate your data projects with the phData Toolkit