In this article, we show you how to turn a flawed AI into a training file. We'll use the Foundry framework to build a simple web application. The code is self-containedIn this article, we show you how to turn a flawed AI into a training file. We'll use the Foundry framework to build a simple web application. The code is self-contained

Your First AI Data Flywheel in Under 100 Lines of Python

Moving from theory to a tangible, working system that turns AI mistakes into high-quality training data.

\ In the first part of this series, we talked about the messy middle of AI development, which is the frustrating gap between a promising 85% prototype and a production-ready 99% system. We established that the key isn't just a better model, but a system that learns from every mistake.

\ Today, we're going to get our hands dirty and construct a simple, working web application that demonstrates the core loop of a data flywheel. By the end of this article, you will have corrected an AI's mistake and generated a perfect, fine-tuning-ready dataset from your work.

\ We'll be using the correction_deck_quickstart example from our open-source framework, Foundry. This example is self-contained, requires no external services like Docker or Redis, and proves just how powerful the core pattern can be.

The Scenario: A Flawed Invoice AI

Imagine we've built an AI to extract structured data from invoices. We feed it an image of an invoice, and we want it to return a clean JSON object. On its first pass, the AI does a decent job, but it's not perfect. It produces this flawed output:

{ "supplier_name": "Lone Star Provisins Inc.", // <-- TYPO! "invoice_number": "785670", "invoice_date": "2025-08-20", "inventory_items": [ { "item_name": "TAVERN HAM WH", "total_quantity": 15.82, "total_unit": "LB", "total_cost": 87.80 }, { "item_name": "ONIONS YELLOW JBO", "total_quantity": 5, // <-- WRONG QUANTITY! Should be 50. "total_unit": "LB", "total_cost": 35.50 } ] }

Our goal is to build a system that allows a human to easily fix these two errors and, crucially, captures those fixes for retraining.

The Three Core Components of Our Flywheel

To build this, our Foundry framework relies on three simple but powerful Python abstractions:

  1. Job: Think of this as a ticket in a tracking system. It's a database model that represents a single unit of work for the AI. It holds the input_data (the invoice image), the initial_ai_output (the flawed JSON above), and a place to store the corrected_output once a human has fixed it.
  2. CorrectionRecord: This is the golden ticket. When a human saves their correction, we don't just update the Job. We create a separate, self-contained CorrectionRecord. This record is purpose-built for fine-tuning. It stores a clean copy of the original input, the AI's bad attempt, and the human's "ground truth" correction. It’s a perfect, portable training example.
  3. CorrectionHandler: This is the business logic. It's a simple class that orchestrates the process: it takes the submitted form data from the web UI, validates it, updates the Job, creates the CorrectionRecord, and handles exporting all the records into a training file.

\ These three pieces work together to form the backbone of our flywheel. Now, let's see them in action.

Let's Build It: The Quickstart in Action

If you're following along, clone the Foundry repository, navigate to the examples/correction_deck_quickstart directory, and install the dependencies.

Step 1: Run the Quickstart Script

From your terminal, simply run:

python quickstart.py

\ You'll see a message that a local web server has started on http://localhost:8000.

--- Foundry Quickstart Server running at http://localhost:8000 --- --- Open the URL in your browser to use the Correction Deck. --- --- Press Ctrl+C to stop the server and complete the flywheel. ---

Step 2: Use the Correction Deck UI

Open that URL in your browser. You'll see a simple Correction Deck UI. On the left is the source invoice image. On the right is a web form pre-filled with the AI's flawed data.

\ Your task is to be the human in the loop. Make these two corrections:

  1. Fix the Typo: Change Lone Star Provisins Inc. to Lone Star Provisions Inc.
  2. Fix the Quantity: Change the quantity for ONIONS YELLOW JBO from 5 to 50.

\ Click Save Correction.

Step 3: Complete the Flywheel

Now, go back to your terminal, and stop the server by pressing Ctrl+C. The script automatically triggers the final step of the flywheel: exporting your work. You'll see this output:

--- Server stopped. --- --- Exporting approved corrections to fine-tuning format... --- --- Data successfully exported to 'corrected_data.jsonl' --- --- QUICKSTART COMPLETE ---

You did it. You just completed one full turn of the data flywheel.

The Payoff: The Perfect Training File

Open the examples/correction_deck_quickstart directory. You'll find a new file: corrected_data.jsonl. This is the prize. This is the tangible result of your work, captured and formatted perfectly for fine-tuning a modern AI model.

\ Let's look inside. It contains a single line of structured JSON:

{"contents": [{"role": "user", "parts": [{"fileData": {"mimeType": "image/jpeg", "fileUri": "/static/example_invoice.jpeg"}}, {"text": "Extract the key business data from the provided input."}]}, {"role": "model", "parts": [{"text": "{\"supplier_name\": \"Lone Star Provisions Inc.\", \"invoice_number\": \"785670\", \"invoice_date\": \"2025-08-20\", \"inventory_items\": [{\"item_name\": \"TAVERN HAM WH\", \"total_quantity\": 15.82, \"total_unit\": \"LB\", \"total_cost\": 87.8}, {\"item_name\": \"ONIONS YELLOW JBO\", \"total_quantity\": 50.0, \"total_unit\": \"LB\", \"total_cost\": 35.5}]}"}]}]}```

\ This might look complex, but it's the exact conversational format that models like Google's Gemino and OpenAI's GPT series expect for fine-tuning.

\

  • "role": "user": This is the prompt. It contains the input image (fileUri) and the instruction we gave the AI.
  • "role": "model": This is the perfect response. It contains the JSON string with your corrections applied.

\ We have successfully turned a few seconds of human effort into a high-quality, machine-readable training example. Now, imagine doing this for 100 corrections. Or 1,000. You are no longer just fixing errors; you are actively and efficiently building a dataset that will eliminate this entire class of errors in the next version of your model.

What's Next?

We've proven the core loop of the flywheel: Correct -> Capture -> Format for Training.

\ This is a powerful start, but it's an offline process. We waited for the AI to finish its batch, and then we corrected its work. But what if we could be more interactive? What if a pipeline could be running, encounter something it doesn't understand, and intelligently pause itself to ask a human for help in real time?

\ In the next article in this series, we'll build exactly that. We will construct a resilient, Human-in-the-Loop pipeline that knows when it's in trouble and isn't afraid to ask for clarification.

Market Opportunity
Sleepless AI Logo
Sleepless AI Price(AI)
$0.04224
$0.04224$0.04224
+0.59%
USD
Sleepless AI (AI) Live Price Chart
Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact service@support.mexc.com for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.

You May Also Like

Is Doge Losing Steam As Traders Choose Pepeto For The Best Crypto Investment?

Is Doge Losing Steam As Traders Choose Pepeto For The Best Crypto Investment?

The post Is Doge Losing Steam As Traders Choose Pepeto For The Best Crypto Investment? appeared on BitcoinEthereumNews.com. Crypto News 17 September 2025 | 17:39 Is dogecoin really fading? As traders hunt the best crypto to buy now and weigh 2025 picks, Dogecoin (DOGE) still owns the meme coin spotlight, yet upside looks capped, today’s Dogecoin price prediction says as much. Attention is shifting to projects that blend culture with real on-chain tools. Buyers searching “best crypto to buy now” want shipped products, audits, and transparent tokenomics. That frames the true matchup: dogecoin vs. Pepeto. Enter Pepeto (PEPETO), an Ethereum-based memecoin with working rails: PepetoSwap, a zero-fee DEX, plus Pepeto Bridge for smooth cross-chain moves. By fusing story with tools people can use now, and speaking directly to crypto presale 2025 demand, Pepeto puts utility, clarity, and distribution in front. In a market where legacy meme coin leaders risk drifting on sentiment, Pepeto’s execution gives it a real seat in the “best crypto to buy now” debate. First, a quick look at why dogecoin may be losing altitude. Dogecoin Price Prediction: Is Doge Really Fading? Remember when dogecoin made crypto feel simple? In 2013, DOGE turned a meme into money and a loose forum into a movement. A decade on, the nonstop momentum has cooled; the backdrop is different, and the market is far more selective. With DOGE circling ~$0.268, the tape reads bearish-to-neutral for the next few weeks: hold the $0.26 shelf on daily closes and expect choppy range-trading toward $0.29–$0.30 where rallies keep stalling; lose $0.26 decisively and momentum often bleeds into $0.245 with risk of a deeper probe toward $0.22–$0.21; reclaim $0.30 on a clean daily close and the downside bias is likely neutralized, opening room for a squeeze into the low-$0.30s. Source: CoinMarketcap / TradingView Beyond the dogecoin price prediction, DOGE still centers on payments and lacks native smart contracts; ZK-proof verification is proposed,…
Share
BitcoinEthereumNews2025/09/18 00:14
Fed Decides On Interest Rates Today—Here’s What To Watch For

Fed Decides On Interest Rates Today—Here’s What To Watch For

The post Fed Decides On Interest Rates Today—Here’s What To Watch For appeared on BitcoinEthereumNews.com. Topline The Federal Reserve on Wednesday will conclude a two-day policymaking meeting and release a decision on whether to lower interest rates—following months of pressure and criticism from President Donald Trump—and potentially signal whether additional cuts are on the way. President Donald Trump has urged the central bank to “CUT INTEREST RATES, NOW, AND BIGGER” than they might plan to. Getty Images Key Facts The central bank is poised to cut interest rates by at least a quarter-point, down from the 4.25% to 4.5% range where they have been held since December to between 4% and 4.25%, as Wall Street has placed 100% odds of a rate cut, according to CME’s FedWatch, with higher odds (94%) on a quarter-point cut than a half-point (6%) reduction. Fed governors Christopher Waller and Michelle Bowman, both Trump appointees, voted in July for a quarter-point reduction to rates, and they may dissent again in favor of a large cut alongside Stephen Miran, Trump’s Council of Economic Advisers’ chair, who was sworn in at the meeting’s start on Tuesday. It’s unclear whether other policymakers, including Kansas City Fed President Jeffrey Schmid and St. Louis Fed President Alberto Musalem, will favor larger cuts or opt for no reduction. Fed Chair Jerome Powell said in his Jackson Hole, Wyoming, address last month the central bank would likely consider a looser monetary policy, noting the “shifting balance of risks” on the U.S. economy “may warrant adjusting our policy stance.” David Mericle, an economist for Goldman Sachs, wrote in a note the “key question” for the Fed’s meeting is whether policymakers signal “this is likely the first in a series of consecutive cuts” as the central bank is anticipated to “acknowledge the softening in the labor market,” though they may not “nod to an October cut.” Mericle said he…
Share
BitcoinEthereumNews2025/09/18 00:23
Coinbase Joins Ethereum Foundation to Back Open Intents Framework

Coinbase Joins Ethereum Foundation to Back Open Intents Framework

Coinbase Payments has joined the Open Intents Framework as a core contributor, working alongside Ethereum Foundation and other major players. The initiative aims to simplify complex multi-chain interactions through automated solver technology. The post Coinbase Joins Ethereum Foundation to Back Open Intents Framework appeared first on Coinspeaker.
Share
Coinspeaker2025/09/18 02:43