3 - Datacleaning n8n

The third Madison framework tutorial covers cleaning messy API data and building retry logic in n8n so your automation workflow survives real-world failures.

4:51 video3 min readWatch on YouTube

An AI agent built on messy data is only as reliable as the mess it was trained on. This third tutorial in the Madison framework series, led by Krithi, tackles the unglamorous but essential work that separates a demo workflow from one that actually holds up: cleaning API data and handling the errors that come with calling real-world APIs.

Why clean data is the foundation

Before touching any n8n nodes, the video makes the case for why this step matters. Common data problems, missing fields, null values, inconsistent formatting, duplicate entries, or irrelevant information, degrade an AI agent's reliability directly. If your project needs to demonstrate improvement in a workflow's success rate, data cleaning is where that improvement actually starts, not an afterthought bolted on at the end.

Cleaning data with a Code node

The demonstration builds directly on a previous workflow in the series that pulled JSON data from an OpenAI-related API. Rather than starting from scratch, a few additional variables and parameters are added to that same API call, which gives the workflow enough messy fields to actually demonstrate a cleaning problem instead of a clean, artificial example. After the HTTP Request node, a Code node running JavaScript is added to do the actual work: it strips out null values and can standardize the response format, including adding timestamps where useful for downstream steps. Executing the workflow confirms the cleaning step works as intended, with the output showing clearly cleaned data compared to what came back from the raw API call.

Building error handling and retry logic

Clean data alone does not protect a workflow from calls that fail outright. The video walks through three complementary approaches available in n8n: an If node that implements a try/catch-style pattern, Error Trigger nodes that activate when something fails, and retry logic for temporary failures. The practical demonstration focuses on retry logic specifically: an If node checks whether an expected ID field is present in the response. If it is, the workflow proceeds to data processing as normal. If it is not, the workflow routes to a second HTTP Request node configured identically to the first, which loops back into the same If node. That loop gives the workflow a way to retry a failed call automatically rather than breaking on the first hiccup.

Testing and documenting improvement

The tutorial closes with a structured approach to proving the changes actually helped, rather than just assuming they did. That means creating a simple testing plan using five to ten different inputs, running the workflow against each one, documenting the results, and calculating a success percentage each time. The process is meant to be repeated: keep testing the API or response data again and again, and document the improvement between versions rather than only reporting a single final number. The video uses a concrete example to make this tangible: a workflow that originally succeeded 70% of the time might improve to 85–90% reliability once error handling and data cleaning are in place. Documenting that jump, not just making it, is presented as essential to demonstrating real progress on a Madison framework contribution.

Where this fits in the larger series

This tutorial sits in the middle of a progression that starts with collecting data from APIs and ends with a workflow ready for production use. Data cleaning and error handling are framed as the step that turns a workflow from something that merely runs into something that can be trusted to run repeatedly, which matters because the next stage in the series is about scaling the same workflow to handle real-world volume and API rate limits.

Key takeaways

  • Missing fields, null values, duplicates, and inconsistent formatting are the main data quality problems to address before trusting a workflow's output.
  • A Code node running JavaScript can strip null values and standardize API responses in place.
  • n8n offers three error-handling patterns: If node try/catch logic, Error Trigger nodes, and retry logic.
  • Connecting an If node back to a second HTTP Request node creates a retry loop that shields a workflow from temporary API failures.
  • Testing with five to ten inputs and calculating a success rate turns "it feels more reliable" into a documented, measurable improvement.

Who this is for

This tutorial is aimed at anyone building or contributing to a Madison framework project in n8n, particularly Humanitarians AI Fellows who need to show measurable reliability improvements in their workflow contributions. The next video in the series moves on to scaling and testing the workflow for production use.

Full transcript(auto-generated, with timestamps)

[0:01]Welcome back to Madison framework tutorial series. I'm Krithi and today we are focusing on making data pipeline more robust. Once you have collected data from APIs, next step is you need to clean it and handle all the potential errors and it is a crucial skill. But before we dive into the techniques, let's talk about why clean data matters for your project. Your AI agent is only as good as the data it learns from. And common data issues include missing fields or null values, inconsistent formatting, duplicate entries or irrelevant information. Clean data improves your agent's reliability and it must be a key focus where you need to demonstrate

[0:43]Improvement in your workflow's success rate. Now let's look at how to clean your API data using n8n nodes. And let me just give a quick demonstration of this and for that I'm going to be building on top of my previous demo. So after this HTTP request node, I'm going to be adding a function node. But before that, uh here I had the API to get the, you know, OpenAI details basically. So yeah, this was the JSON data that I was getting basically. So I'm going to add a few more variables and parameters to the same API. If you see, uh it's the same but I've just

[1:23]Added few more fields just to explain the concept of this demo. Yeah, so now this will be helpful for uh you know, showing the cleaning of the data basically. That's it. And let me proceed with adding a code which is uh I'm choosing JavaScript and basically this is uh the code that I'll be using to clean the data from my API and this will remove all the null values and uh if I want to add some timestamps or standardize all the response, then this code will perform all those functions. Yep, that's it and let me just execute. Yes, this workflow is successfully executed. As you can see, the data is cleaned.

[2:09]Now, let's make our workflow more reliable by handling errors. And this is a very crucial step where you need to improve your workflow success rate. And there are several approaches in N8N. You there is a if node that will handle this try catch pattern. And there are error trigger nodes that activate some when something is failing. And there's also a retry logic that you can handle uh temporary failures. Now, let's implement a basic retry system. Back to our demo. And after this HTTP request, I'm going to be adding a if node. So, I'm checking whether my ID field is present. So, if yes, then it is proceeding to,

[2:59]You know, our data processing, first cleaning and then uh processing. But if no, I'm going to be adding another HTTP request node. Basically, the same thing. I'm calling the same API and uh requesting the same data. And don't forget these steps I explained in my previous video. Yes, now this request node HTTP request node has the same settings. And I'm going to be connecting this back to the if node. And that will create a retry loop. Now, this will give your workflow resilience against any temporary failures. Next step is you need to document your success rate improvements. And here's how to test your workflow. Start by creating a simple testing plan

[3:51]With five to 10 different inputs. Run your workflow with each input and document results and calculate your success percentage. Keep on making improvements and testing the API or response data again and again, and don't forget to document the improvement between each versions. For example, you might find your original workflow succeed 70% of the time, but with error handling and data cleaning, it improves to 85 to 90% of the reliability. By now, you have the skills to clean the data and handle errors in any 10 workflows. These improvements are essential for your project where you need to demonstrate increased reliability in medicine framework contribution. In our next video, we'll explore scaling

[4:35]Your workflow and preparing it for production use. Remember, your goal is to transform your workflow from a basic MVP to something robust enough for real-world deployment. Up next is scaling and testing your n8n workflow. Thank you so much for watching this video. I hope this was helpful.

More from INFO7375 Branding & AI

Humanitarians AI Lyrical Literacy Project