How do I stop bad rows from burning money in an n8n AI batch?
Short answer: put a validation step between "read the sheet" and "call the paid API". For each row, look up the rules for the model that row targets (allowed durations, resolutions, aspect ratios, whether audio or a reference image is supported, prompt length), check the row against them, and split the batch in two. Valid rows go to the paid call. Invalid rows go back to the sheet with status rejected and a plain reason, and nothing is spent on them.
This came up in r/n8n on 15 November 2026. A builder running batch video through n8n, with some rows going to Seedance 2.5 and some to Kling 4.0, put it this way: a row that is fine for one model is "a 400 error, or worse a valid but wrong render, for another" (thread). A day earlier, another r/n8n thread asked for people's most expensive n8n mistake, listing "duplicate emails, lost leads, incorrect invoices", with a bonus for cases where "n8n said the execution was successful" (thread).
Why a 400 is the cheap failure
| What happens | Cost |
|---|---|
| API rejects the row with a 400 | Usually free, but the batch may stop or retry |
| API accepts a row it silently adjusts (wrong duration, cropped ratio, audio dropped) | You pay for a render you cannot use |
| Retry logic re-sends a bad row several times | You pay for the same failure again |
| Row is valid but a duplicate of one already rendered | You pay twice for the same output |
The expensive cases are the ones the API accepts. That is why the check belongs in your workflow, before the call, not in the provider's error handling.
The pattern
- Keep model rules in one place. A small JSON object (or a "Model Rules" sheet tab) keyed by model name. Fill the values from each provider's current documentation, and record the date you checked, because limits change between model versions.
-
Normalize the row first. Trim strings, lowercase the model name, turn "10s" into
10, turn "yes"/"TRUE" intotrue. Most rejects are formatting, not intent. - Validate against the rules for that row's model. Unknown model, value not in the allowed list, reference image required but missing, prompt too long: each one becomes a short reason string.
-
Skip what you already paid for. Hash the normalized row (model + prompt + settings). If the hash is already marked
donein your sheet or database, skip it. -
Split, then spend. Use an IF node on
valid. The true branch goes to the paid call. The false branch writesrejectedand the reasons back to the sheet. - Cap the batch. Before the paid branch, count the valid rows and stop if the count is above a limit you set, so a pasted sheet of 2,000 rows cannot run by accident.
The rules object
The values below are placeholders, not real model limits. Replace them with what each provider documents today.
{
"checked_on": "YYYY-MM-DD",
"models": {
"model-a": {
"durations": [5, 10],
"resolutions": ["720p", "1080p"],
"aspect_ratios": ["16:9", "9:16", "1:1"],
"audio": true,
"reference_image": "optional",
"max_prompt_chars": 2000
},
"model-b": {
"durations": [5],
"resolutions": ["720p"],
"aspect_ratios": ["16:9", "9:16"],
"audio": false,
"reference_image": "required",
"max_prompt_chars": 1500
}
}
}
The Code node
Run this in "Run Once for All Items" mode. It reads the rules from a previous node named Model Rules.
const rules = $('Model Rules').first().json.models;
const out = [];
for (const item of $input.all()) {
const r = item.json;
const row = {
...r,
model: String(r.model || '').trim().toLowerCase(),
prompt: String(r.prompt || '').trim(),
duration: parseInt(String(r.duration || '').replace(/[^0-9]/g, ''), 10),
resolution: String(r.resolution || '').trim().toLowerCase(),
aspect_ratio: String(r.aspect_ratio || '').trim(),
audio: ['true', 'yes', '1'].includes(String(r.audio).trim().toLowerCase()),
reference_image: String(r.reference_image || '').trim(),
};
const reasons = [];
const m = rules[row.model];
if (!m) {
reasons.push(`unknown model "${row.model}"`);
} else {
if (!row.prompt) reasons.push('empty prompt');
if (row.prompt.length > m.max_prompt_chars) reasons.push(`prompt over ${m.max_prompt_chars} chars`);
if (!m.durations.includes(row.duration)) reasons.push(`duration ${row.duration} not in [${m.durations}]`);
if (!m.resolutions.includes(row.resolution)) reasons.push(`resolution ${row.resolution} not allowed`);
if (!m.aspect_ratios.includes(row.aspect_ratio)) reasons.push(`aspect ratio ${row.aspect_ratio} not allowed`);
if (row.audio && !m.audio) reasons.push('audio not supported by this model');
if (m.reference_image === 'required' && !row.reference_image) reasons.push('reference image required');
if (m.reference_image === 'none' && row.reference_image) reasons.push('reference image not supported');
}
const key = [row.model, row.prompt, row.duration, row.resolution, row.aspect_ratio, row.audio, row.reference_image].join('|');
out.push({ json: { ...row, row_key: key, valid: reasons.length === 0, reasons: reasons.join('; ') } });
}
return out;
For the duplicate check, compare row_key (or a hash of it) against rows already marked done before the IF node. For the batch cap, add a Code node on the valid branch that throws if $input.all().length is above your limit.
Quick test
Make a five-row test sheet: one valid row per model, one row with an unknown model name, one with a duration the model does not support, and one exact copy of a valid row that is already marked done. Run the workflow with the paid node disabled. You should see two rows on the valid branch, two rejected with clear reasons in the sheet, and one skipped as a duplicate. Only then enable the paid node.
Doing it in Make
The same pattern works in Make: a Google Sheets "Search Rows" module, a Data Store holding the model rules, a router with filters per rule (or one "Set multiple variables" step that builds the reason string), and a filter so only rows with an empty reason reach the paid HTTP module. Rejected rows go to an "Update a Row" module. You can build it on the free plan: Make free plan.
Disclosure: Some links are affiliate links — I may earn a commission at no extra cost to you.
Top comments (0)