earendil-works/pi · error

Tool " " cannot use grammar constrained sampling: .

Error message

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

What it means

After choosing a grammar variant (preferring lark), the builder validates the definition; a malformed or rejected definition surfaces here with the underlying message embedded. The tool declares grammar sampling but its grammar text cannot be used by the provider.

Solutions

  1. Address the embedded message: adjust the tool schema or the grammar configuration.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

	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,
	supportsOpenAIGrammarTools: boolean,
): ReadonlyMap<string, string> {
	const properties = new Map<string, string>();
	for (const tool of tools ?? []) {
		const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
		if (grammar) {
			properties.set(tool.name, grammar.inputProperty);
		}
	}
	return properties;
}

View on GitHub (pinned to 4af9d21d3b)