How to Extract Data from Images in Airtable using AI

Jul 25, 2024Zayyad Muhammad Sani

In this tutorial, you'll learn how to extract data from images in Airtable using OpenAI. You'll extract specific data such as the name, email, and job title from pictures of business cards.

Here's one of the images we'll work with.

business card 1-resized.png

You can follow the steps in this tutorial to extract structured data from any image.

Setting up the Images Table

We'll begin by uploading the business card images to Airtable.

1. Create a table called "Business cards" or use an existing table.

2. Create a new field called "Business card" with the type Attachment. You can use an existing attachment field if you have one.

3. Upload the images to the "Business card" field.

uploaded-business-card-images.png

4. Create a new Grid view called Needs data and apply the following filters:

  • Name - is empty
  • Business card - is not empty
needs-data-business-cards.png

We'll use this view to extract data from the business cards that don't have information in the table.

Now that the table is set up, we can connect to OpenAI with Data Fetcher.

Add Data Fetcher to Airtable

We'll create an OpenAI request in Data Fetcher to extract data from the business cards we uploaded. To get started:

1. Add the Data Fetcher extension to your Airtable base.

2. Once you’ve added the extension, sign in to Data Fetcher or sign up if you don’t have an account.

sign up for data fetcher.png

3. Once you're logged in to Data Fetcher, click Create your first request.

create your first request logo 2 smaller.png

Extract Data from Images in Airtable using AI

Follow these steps to configure the request:

1. Select OpenAI under Application.

open ai application.png

2. Rename the request to "Extract image data".

rename-extract-image-data.png

3. Copy and paste your OpenAI API key under Authorization. You can create an API key in your OpenAI account.

api key authorization.png

4. Under Endpoint, select Create chat message completion.

ChatGPT-Airtable-Integration5.jpg

5. Click Save and Continue in the bottom right corner.

save-and-continue-business-cards.png

Sending Messages to OpenAI

Once you've completed the previous steps, you'll be taken to a new section to give the AI instructions for extracting data from the business cards.

1. Select gpt-4o-mini under Model.

gpt-4o-mini.png

2. Add the following instruction under Messages:

Extract data from this business card:

first-part-of-message-business-card.png

We'll now reference the "Business card" field.

3. Click the + button next to Messages.

add-reference-business-card-openai-message.png

4. In the dialog that opens, select Business card under Field.

5. Under Run for every record in view, select Needs data.

insert-business-card-reference.png

6. Click Confirm to save the options and close the dialog. We'll now fill in the remaining instructions.

7. Press Shift + Enter on your keyboard to go to the next line, then copy and paste the following code:

Return data in a JSON format. If you cannot find a field, return null.
Output format:
{
 "name": "TODO",
 "jobTitle": "TODO",
⁠ "contactEmail": "TODO"
}
complete-message-business-card-request.png

8. Press Enter to add the message, then click Save and Run in the bottom right corner to proceed.

Let's walk through the message above before moving on. We're asking OpenAI to extract the name, job title, and email from a business card, which we attached by referencing the "Business card" field in the Needs data view.

We then ask it to return the results in JSON format so that Data Fetcher can process them properly. Finally, we give it the output format, where we specify the data we want from the images.

TIP: You can use the format above to extract data from other images, as long as they have structured data.

Mapping Response Fields

After following the previous steps, Data Fetcher will take you to Response field mapping. On this page, you'll choose the fields from the response data you want in your table.

response-field-mapping-business-cards.png

Data Fetcher returned many fields from the request, but we're only interested in the name, contact email, and job title fields. Notice how these fields have the word "Json" in their names.

first-three-fields-business-cards.png

Data Fetcher automatically added this prefix because we instructed OpenAI to return a JSON response in the message we created earlier.

Follow these steps to import the fields:

1. Click Deselect all.

deselect-all-business-cards.png
  • 2. Select the following fields and use the mapping below:
  • Json name -> Existing field Name
  • Json job title -> New field Job title
  • Json contact email -> New field Contact email
fields-to-import-business-card.png

3. Click Save and Run in the bottom right corner.

Check the default view of your output table and you should see the extracted data.

data-extracted-business-cards.png

Next Steps

You may want to extract the data automatically whenever you add new images to your table. In that case, check out Data Fetcher's trigger feature. Triggers will automatically run the request when data changes in your table, saving you time to do other things. Check out our help center to learn more about triggers and scheduling.

Related Posts

Extract Data from PDFs to Airtable using OpenAI

Extract Data from PDFs to Airtable using OpenAI

Jul 18, 2024

Zayyad Muhammad Sani

OpenAIPDF
How to Use Airtable Generative AI

How to Use Airtable Generative AI

Jul 5, 2024

Andy Cloke

OpenAI
Connect to the OpenAI API in Airtable with No-Code

Connect to the OpenAI API in Airtable with No-Code

Jun 25, 2024

Andy Cloke

OpenAI