AI Data Extraction with Dynamic Prompts and Airtable n8n Workflow Template

n8n workflow template · 32 nodes · OpenAI

AI Data Extraction with Dynamic Prompts and Airtable is a free n8n workflow template that starts when its webhook receives an HTTP request and works with OpenAI and Airtable. It has 32 nodes, 4 of them AI nodes (Basic LLM Chain and OpenAI Chat Model). The notes inside the workflow say: “To link this workflow with Airtable, you'll have to create webhooks for the Base. You'll only really need to do this this once but if these webhooks are inactive after 7 days, you'll need to create them again.” To run it, you add your own credentials for Airtable API and OpenAI API.

At a glance

Trigger
Webhook (Airtable Webhook)
Nodes
32
Apps
OpenAI and Airtable
AI nodes
4
Credentials
2 types
Category
Spreadsheets, databases and docs

Apps and integrations

  • OpenAI
  • Airtable

Node types used

  • Switch
  • Code
  • HTTP Request
  • Extract from File
  • Edit Fields (Set)
  • Loop Over Items
  • Basic LLM Chain
  • Filter
  • OpenAI Chat Model
  • Airtable
  • Webhook
  • Manual Trigger

How it works

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

⭐ Creating Airtable Webhooks

To link this workflow with Airtable, you'll have to create webhooks for the Base. You'll only really need to do this this once but if these webhooks are inactive after 7 days, you'll need to create them again.

Check out the Airtable Developer documentation for more info

1. Get Table Schema

Learn more about the Airtable node

For this operation, we'll use the handy Airtable node. I recommend getting familiar with this node for all your Airtable needs!

2. Event Router Pattern

Learn more about the Switch node

A simple switch node can be used to determine which event to handle. The difference between our row and field events is that row event affect a single row whereas field events affect all rows.

2b. Update Every Row under the Field

This branch updates all applicable rows under field when the field/column is created or changed. Watch out - if you have 1000s of rows, this could take a while!

2a. Updates Minimal Number of Rows

This branch updates only the rows impacted.

3. Filter Only Rows with Valid Input

Learn more about the Split Out node

This step handles one or more updated rows where "updated" means the "input" column (ie. "file" in our example) for these rows were changed. For each affected row, we'll get the full row to figure out only the columns we need to update - this is an optimisation to avoid redundant work ie. generating values for columns which already have a value.

7. Listing All Applicable Rows Under The Column

Learn more about the Filter node

To keep things performant, we can decide to get only rows with inputfield populated as this is required to perform the extraction. This can easily be achieved with Airtable filters.

8. Using an Items Loop

Learn more about the Split in Batches node

Similar to Step 4, the Split in Batches node is a preference for user experience - changes are seen in the Airtable quicker.

4. Using an Items Loop

Learn more about the Split in Batches node

A split in batches node is used here to update a row at a time however, this is a preference for user experience - changes are seen in the Airtable quicker.

9. Generating Value using LLM

Learn more about the Extract From File node

Pretty much identical to Step 5 but instead of updating every field/column, we only need to generate a value for one.

5. PDFs, LLMs and Dynamic Prompts? Oh My!

Learn more about the Basic LLM node

This step is where it all comes together! In short, we give our LLM the PDF contents as the context and loop through our dynamic prompts (from the schema we pulled earlier) for our row. At the end, our LLM should have produced a value for each column requested.

Note: There's definitely a optimisation which could be done for caching PDFs but it beyond the scope of this demonstration.

10. Update the Airtable Record

Learn more about the Edit Fields node

As with Step 6, the LLM response is used to update the row however only under the field that was created/changed. Once complete, the loop continues and the next row is processed.

6. Update the Airtable Record

Learn more about the Edit Fields node

Finally, we can collect the LLM responses and combine them to build an API request to update our Airtable record - the Id of which we got from initial webhook. After this is done, we can move onto the next row and repeat the process.

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Try It Out!

This n8n template powers a "dynamic" or "user-defined" prompts with PDF workflow pattern for a Airtable table. Simply put, it allows users to populate a spreadsheet using prompts without touching the underlying template.

Check out the video demo I did for n8n Studio

Check out the example Airtable here

This template is intended to be used as a webhook source for Airtable. Looking for a Baserow version? Click here

How it works

  • Each Airtable.io tables offers integration feature whereby changes to the table can be sent as events to any accessible webhook. This allows for a reactive trigger pattern which makes this type of workflow possible. For our usecase, we capture the vents of row_updated, field_created and field_updated.
  • Next, we'll need an "input" column in our Airtable.io table. This column will be where our context lives for evaluating the prompts against. In this example, our "input" column name is "file" and it's where we'll upload our PDFs. Note, this "input" field is human-controlled and never updated from this template.
  • Now for the columns (aka "fields" in Airtable). Each field allows us to define a name, type and description and together form the schema. The first 2 are self-explaintory but the "description" will be for users to provide their prompts ie. what data should the field to contain.
  • In this template, a webhook trigger waits for when a row or column is updated. The incoming event comes with lots of details such as the table, row and/or column Ids that were impacted.
  • We use this information to fetch the table's schema in order to get the column's descriptions (aka dynamic prompts).
  • For each triggered event, we download our input ie. the PDF and ready it for our AI/LLM. By iterating through the available columns and feeding the dynamic prompts, our LLM can run those prompts against the PDF and thus generating a value response for each cell.
  • These values are then collected and used to update the Airtable Record.

How to use

  • You'll need to publish this workflow and make it accessible to our Airtable instance.
  • you must run the "Create Airtable Webhooks" mini-flow to link it to your Airtable.
  • This template is reusable for other Airtables but the webhooks need to be created each time for each table.

Need Help?

Join the Discord or ask in the Forum!

Nodes in this workflow

The 32 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Event Type (Switch)
  2. Get Prompt Fields (Code)
  3. Get File Data (HTTP Request)
  4. Extract from File (Extract from File)
  5. Get Result (Edit Fields (Set))
  6. Loop Over Items (Loop Over Items)
  7. Generate Field Value (Basic LLM Chain)
  8. Fields to Update (Code)
  9. Loop Over Items1 (Loop Over Items)
  10. Get File Data1 (HTTP Request)
  11. Extract from File1 (Extract from File)
  12. Get Result1 (Edit Fields (Set))
  13. Generate Field Value1 (Basic LLM Chain)
  14. Filter Valid Rows (Filter)
  15. Filter Valid Fields (Filter)
  16. OpenAI Chat Model (OpenAI Chat Model)
  17. OpenAI Chat Model1 (OpenAI Chat Model)
  18. Get Webhook Payload (HTTP Request)
  19. Parse Event (Code)
  20. Get Table Schema (Airtable)
  21. Fetch Records (Airtable)
  22. Update Row (Airtable)
  23. Get Row (Airtable)
  24. Add Row ID to Payload (Edit Fields (Set))
  25. Update Record (Airtable)
  26. Airtable Webhook (Webhook)
  27. When clicking ‘Test workflow’ (Manual Trigger)
  28. Set Airtable Vars (Edit Fields (Set))
  29. Get Table Schema1 (Airtable)
  30. Get "Input" Field (Edit Fields (Set))
  31. RecordsChanged Webhook (HTTP Request)
  32. FieldsChanged Webhook (HTTP Request)

Credentials you need

  • Airtable API – used by Fetch Records, FieldsChanged Webhook, Get Row and Get Table Schema and others
  • OpenAI API – used by OpenAI Chat Model and OpenAI Chat Model1

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us