Automate GPT-4o Fine-Tuning with Google Sheets or Airtable Data

Nodes

3b9f1b78-6b80-4575-aa6c-966987000389eb4d7d31-2fbb-4c15-b894-0022be7a4ecf2e3e39e3-0e17-4fae-9ac5-9ee31f9711ed+3

Created by

MaMatty Reed

Last edited 39 days ago

Who is this for?

Anyone curating before/after text examples in a spreadsheet and wanting a push-button path to a fine-tuned GPT model—without touching curl. Works with Google Sheets or Airtable.


What problem does it solve?

Manually downloading CSVs, converting to JSONL, uploading, and polling OpenAI is a slog.
This flow automates the whole loop: grab examples flagged Ready, build the JSONL file, start the fine-tune, then log the resulting model ID back to a registry sheet/table for reuse.


How it works

| # | Node | Purpose | |---|------|---------| | 1 | Schedule Trigger | Runs weekly by default (change as needed). | | 2a | Get Examples from Sheet | Pulls rows where Ready = TRUE from your Google Sheet. Uses the JSONL-Template Sheet as the expected column layout. | | 2b | Get Examples from Airtable (disabled) | Alternate source for Airtable users. | | 3 | Create JSONL File (Code) | Converts each example to chat-format JSONL and splits into train.jsonl / val.jsonl (80/20). | | 4 | Upload JSONL | Uploads the training file to OpenAI (purpose: fine-tune). | | 5 | Begin Fine-Tune | Starts a fine-tune job on gpt-4o (editable). | | 6 | Wait → Check Job → IF | Polls every minute until status = succeeded. | | 7a | Write Model to Sheet | Appends the new model ID + meta to your Model Registry sheet. | | 7b | Write Model to Airtable (disabled) | Equivalent logging step for Airtable. |


Setup steps

  1. Import & connect credentials

    • Import the JSON flow into n8n.
    • Add your OpenAI API key.
    • Google Sheets: create an OAuth2 credential and link it to both Sheets nodes.
    • Airtable (optional): create a Personal Access Token and attach it to the Airtable nodes.
  2. Copy the template sheet

    • Duplicate the JSONL-Template Sheet linked above into your own Drive.
    • Required columns (exact names):
      | systemPrompt | userPrompt | assistantResponse | Ready |
    • Tick Ready = TRUE for rows you want to include.
  3. Create the registry sheet/table

    • Google Sheet (or Airtable table) named Model Registry with columns:
      Model ID, Training Examples, Epochs, Batch Size, Learning Rate, Finished At.
  4. Tweak model & schedule

    • Change the base model in Begin Fine-Tune if desired.
    • Adjust the Schedule Trigger for daily / on-demand runs.
  5. Test it

    • Mark a few examples Ready = TRUE.
    • Run the flow manually.
    • Check OpenAI for the new fine-tune job and confirm the model ID is logged in your registry.

Resources


Extending the flow

  • Webhook trigger – swap the schedule for a webhook to train on demand.
  • Multi-source merge – enable both Sheets and Airtable nodes to combine datasets.
  • Auto-deploy – save the new model name to an env-var or Secrets Manager for downstream generation workflows.

New to n8n?

Need help building new n8n workflows? Process automation for you or your company will save you time and money, and it's completely free!