earendil-works/pi · error

grammar tool input for property "${inputProperty}" changed n

Error message

grammar tool input for property "${inputProperty}" changed non-monotonically

What it means

Error "grammar tool input for property "${inputProperty}" changed non-monotonically" thrown in earendil-works/pi.

Source

Thrown at packages/ai/src/api/constrained-sampling.ts:168

	const input = arguments_[inputProperty];
	if (typeof input !== "string") {
		throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
	}
	return input;
}

export function appendGrammarToolInputJsonDelta(
	buffer: GrammarToolInputJsonBuffer,
	inputProperty: string,
	nextInput: string,
	close: boolean,
): string | undefined {
	if (buffer.closed) {
		if (close && nextInput === buffer.input) return undefined;
		throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
	}
	if (!nextInput.startsWith(buffer.input)) {
		throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
	}

	const inputDelta = nextInput.slice(buffer.input.length);
	if (!close && inputDelta.length === 0) return undefined;

	let delta = "";
	if (!buffer.started) {
		delta += `{${JSON.stringify(inputProperty)}:"`;
		buffer.started = true;
	}
	delta += JSON.stringify(inputDelta).slice(1, -1);
	buffer.input = nextInput;

	if (close) {
		delta += '"}';
		buffer.closed = true;
	}
	return delta;

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Ensure grammar tool input only grows by appending; never rewrite earlier content.

When it happens

Trigger: Thrown at packages/ai/src/api/constrained-sampling.ts:168 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/6280989538f86ac0. Report an issue: GitHub.