earendil-works/pi · error
Tool " " cannot use grammar constrained sampling: no…
Error message
Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided. What it means
resolveGrammarConstrainedSampling throws when a grammar tool supplies no usable variant: both openai_lark and openai_regex are missing, non-strings, or blank. With no grammar definition there is nothing to constrain sampling with, so the tool cannot be dispatched to a grammar-capable provider.
Solutions
- Provide a supported grammar variant for the tool.
Defensive patterns
Strategy: validation
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.
Appendix: 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)