AI Data Extraction with Dynamic Prompts and Baserow n8n Workflow Template

n8n workflow template · 26 nodes · OpenAI

AI Data Extraction with Dynamic Prompts and Baserow is a free n8n workflow template that starts when its webhook receives an HTTP request and works with OpenAI. It has 26 nodes, 4 of them AI nodes (Basic LLM Chain and OpenAI Chat Model). The notes inside the workflow say: “For this operation, we'll have to use the Baserow API rather than the built-in node. However, this way does allow for more flexibility with query parameters.” To run it, you add your own credentials for HTTP Header Auth and OpenAI API.

At a glance

Trigger
Webhook (Baserow Event)
Nodes
26
Apps
OpenAI
AI nodes
4
Credentials
2 types
Category
AI agents and LLM tools

Apps and integrations

  • OpenAI

Node types used

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

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.

1. Get Table Schema

Learn more about the HTTP node

For this operation, we'll have to use the Baserow API rather than the built-in node. However, this way does allow for more flexibility with query parameters.

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 Rows Under The Column

Learn more about the Code node

We can use Baserow's List API and the HTTP node's pagination feature to fetch all applicable rows under the affected field - the filter query on the API is helpful here.

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 Baserow quicker.

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 Baserow quicker.

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.

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.

10. Update the Baserow Table Row

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 Baserow Table Row

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 Baserow Table row - 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 Baserow 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

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

How it works

  • Each Baserow.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 Baserow.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 Baserow). 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 Baserow Table.

How to use

  • You'll need to publish this workflow and make it accessible to our Baserow instance. Good to note, you only really need to do this once and can reuse for many Baserow Tables.
  • Configure your Baserow Table to send row_updated, field_created and field_updated events to this n8n workflow.
  • This workflow should work with both cloud-hosted and self-hosted versions of Baserow.

Need Help?

Join the Discord or ask in the Forum!

⭐ Creating Baserow Webhooks

Baserow webhooks are created via the UI and the option can be accessed by clicking on the 3 dots button in the toolbar.

  • Create a POST webhook for your n8n webhook URL found in this template.
  • Select the "use fields names instead of IDs" option.
  • Select "let me choose individual events"
  • The events to choose are "row updated", "field created" and "field updated".
  • For the "row updated" event, be sure to specify the input field - in this case, "File".

Nodes in this workflow

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

  1. Baserow Event (Webhook)
  2. Event Type (Switch)
  3. Table Fields API (HTTP Request)
  4. Get Prompt Fields (Code)
  5. Get Event Body (Edit Fields (Set))
  6. List Table API (HTTP Request)
  7. Get Valid Rows (Code)
  8. Get File Data (HTTP Request)
  9. Extract from File (Extract from File)
  10. Update Row (HTTP Request)
  11. Get Result (Edit Fields (Set))
  12. Loop Over Items (Loop Over Items)
  13. Generate Field Value (Basic LLM Chain)
  14. Get Row (HTTP Request)
  15. Rows to List (Split Out)
  16. Fields to Update (Code)
  17. Loop Over Items1 (Loop Over Items)
  18. Get File Data1 (HTTP Request)
  19. Extract from File1 (Extract from File)
  20. Update Row1 (HTTP Request)
  21. Get Result1 (Edit Fields (Set))
  22. Generate Field Value1 (Basic LLM Chain)
  23. Filter Valid Rows (Filter)
  24. Filter Valid Fields (Filter)
  25. OpenAI Chat Model (OpenAI Chat Model)
  26. OpenAI Chat Model1 (OpenAI Chat Model)

Credentials you need

  • HTTP Header Auth – used by Get Row, List Table API, Table Fields API and Update Row 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