earendil-works/pi · error

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

Error message

grammar tool input for property "${inputProperty}" changed after it was closed

What it means

Error "grammar tool input for property "${inputProperty}" changed after it was closed" thrown in earendil-works/pi.

Source

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

	arguments_: Record<string, unknown>,
	inputProperty: string,
): string {
	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 += '"}';

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Do not modify a grammar input property after it was closed; start a new tool call.

When it happens

Trigger: Thrown at packages/ai/src/api/constrained-sampling.ts:165 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/e1198d26a2613b62. Report an issue: GitHub.