n8n-io/n8n · error · Error

replacements[ ] is missing a valid "new_str" string. Each…

Error message

replacements[${i}] is missing a valid "new_str" string. Each replacement must have {old_str: string, new_str: string}.

What it means

Per-item validation error from parseStrReplacements. It fires when entry i has a valid old_str but its new_str is missing or not a string. Same shape contract as the old_str check, applied to the replacement value.

Solutions

  1. Add a string "new_str" to the replacement at the given index.
  2. Check for typos in the key name (e.g. "newString" instead of "new_str").
  3. Ensure each object in the array has both old_str and new_str as strings.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:200 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/2715de447bbc87f7. Report an issue: GitHub.

Appendix: source

Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:200

	}

	if (!isUnknownArray(parsed)) {
		throw new Error(
			'replacements must be an array of {old_str, new_str} objects. Example: {"replacements": [{"old_str": "foo", "new_str": "bar"}]}',
		);
	}

	const replacements: StrReplacement[] = [];

	for (let i = 0; i < parsed.length; i++) {
		const item = parsed[i];
		if (!isObjectRecord(item) || typeof item.old_str !== 'string') {
			throw new Error(
				`replacements[${i}] is missing a valid "old_str" string. Each replacement must have {old_str: string, new_str: string}.`,
			);
		}
		if (typeof item.new_str !== 'string') {
			throw new Error(
				`replacements[${i}] is missing a valid "new_str" string. Each replacement must have {old_str: string, new_str: string}.`,
			);
		}
		replacements.push({ old_str: item.old_str, new_str: item.new_str });
	}

	return replacements;
}

export class TextEditorDocument {
	private text: string | null;
	private readonly options: TextEditorDocumentOptions;

	constructor(options: TextEditorDocumentOptions = {}) {
		this.text = options.initialText ?? null;
		this.options = options;
	}

View on GitHub (pinned to 5ac6606e81)