earendil-works/pi · error

Tool "${tool.name}" cannot use grammar constrained sampling:

Error message

Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.

What it means

Error "Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided." thrown in earendil-works/pi.

Source

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

export function resolveGrammarConstrainedSampling(
	tool: Tool,
	supportsOpenAIGrammarTools: boolean,
): GrammarConstrainedSampling | undefined {
	const config = tool.constrainedSampling;
	if (!config || config.type !== "grammar") {
		return undefined;
	}

	if (!supportsOpenAIGrammarTools) {
		return undefined;
	}

	const larkDefinition = config.variants.openai_lark;
	const regexDefinition = config.variants.openai_regex;
	const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
	const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
	if (!hasLarkDefinition && !hasRegexDefinition) {
		throw new Error(
			`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`,
		);
	}

	try {
		return {
			format: hasLarkDefinition ? "lark" : "regex",
			definition: hasLarkDefinition ? larkDefinition : regexDefinition!,
			inputProperty: inferGrammarInputProperty(tool),
		};
	} catch (error) {
		const message = error instanceof Error ? error.message : String(error);
		throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
	}
}

export function createGrammarToolInputProperties(
	tools: Tool[] | undefined,

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Provide a supported grammar variant for the tool.

When it happens

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