How to use AI to extract data from emails

Thijs van As
Thijs van As
Founding Head of Product

AI steps in let you harness the power of LLMs like GPT, Gemini, Claude, or LLaMA within your workflows. This tutorial explains how to extract structured information from invoice emails and add that to a spreadsheet.

1. Set up an ‘Email Received’ trigger

First, set up an ‘Email Received’ trigger for Gmail or Outlook, depending on where you receive your invoice emails.

Set up an 'Email received' trigger for Gmail or Outlook

Since we only want to run this workflow for emails containing an invoice, you’ll need to add one or more filters to the trigger. For example, add a filter for the message body containing the word “invoice” or based on the presence of an “invoices” label.

Add filters to the trig

After configuring the filters, the ‘Preview’ section in the trigger panel will show a few recent emails that match the filters above.

The 'Preview' section shows recent emails that match the specified trigger filters

Clicking on an email will open an object inspector dialog showing all the email fields that will be accessible in the remainder of the playbook, as well as the value of each field for the preview email you clicked on. There’s also an ‘Open in Gmail’ button that lets you open the email in Gmail.

The object inspector shows all available fields for an 'Email' object as well as the values for the specific example email that was selected

2. Configure an ‘AI Extract’ step

After setting up the trigger, add an ‘AI Extract’ step to the workflow. This step makes it very easy to extract information from any resource, such as an email or a document.

Add an 'AI Extract' step to extract data from a source

Select an AI model

The first thing to decide is which AI model to use. Free reasonable use of both GPT-3.5 and GPT-4 is included in all plans, including our free plan. You may also use any other model by signing in with your own account with the model provider. In our experience, GPT, Claude 3, and Gemini 1.5 models work best for extraction.

Select an AI model to use. Free reasonable use of GPT-3.5 and GPT-4o is included in all plans

Specify the extraction source

Next, we’ll need to specify where we want to extract data from. In our case, we’re going to extract data from the invoice email we received that triggered the workflow run.

You’ll likely want to select ‘Entire email’, as it will include all metadata of the email, including any attachments it might have. You may also choose to be more specific, such as only picking the message body as the extraction source.

Select the source where you want to extract data from

Define what data should be extracted

And finally, we’ll need to specify which data we want to extract from the email. To do so, we’ll need

  1. Give a description of the data we want to extract
  2. Specify the ‘type’ of said data (e.g. whether we expect text, a number, or a date)

Let’s say we want to extract the following data from the invoice email:

  • The vendor name as text
  • The amount as a number
  • The due date as a date
  • Whether the invoice has been paid as a boolean

Each of these fields may be set to be required (default) or optional. In the latter case, the step will still continue if the AI model is unable to extract this piece of information from the source.

Specify what data should be extracted

We can also optionally tell the step to continue executing the run in case the AI model gives an error.

3. Configure a ‘Google Sheets - Add row to spreadsheet’ step

Lastly, we’ll want to add the extracted information to a spreadsheet.

An example invoice tracking spreadsheet

After adding a Google Sheets ‘Add row to spreadsheet’ step and selecting the right spreadsheet, we’ll select all the columns to populate.

Select all column headers from the spreadsheet

Using data from the AI model’s response

When populating the individual columns, we can easily refer to the data that was extracted by the AI model via the ‘Model response’ object in the data picker.

Wire up the outputs from the AI model into the spreadsheet fields

4. Test your workflow

After you’ve wired up all inputs in the Google Sheets step, it’s time to test the workflow. To do so, click ‘Start a test run’ and select a recent invoice email.

Click 'Start a test run' to test your workflow

Next, click ‘Create test run’ and see how the information from that email is extracted and automatically added to the spreadsheet.

Results of a completed test run

And that’s it! All that’s left is turning on the workflow and invoice information from all newly incoming invoice emails will be automatically extracted and inserted into the spreadsheet.

Finally, turn on the workflow

What will you automate?

Sign up and get started with your first workflow today.
Background imageBackground image