{"record":{"id":"bcbf9efd57157042","repo":"earendil-works/pi","slug":"tool-tool-name-cannot-use-grammar-constrained-bcbf9e","errorCode":null,"errorMessage":"Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.","messagePattern":"Tool \"(.+?)\" cannot use grammar constrained sampling: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ai/src/api/constrained-sampling.ts","lineNumber":261,"sourceCode":"\tconst larkDefinition = config.variants.openai_lark;\n\tconst regexDefinition = config.variants.openai_regex;\n\tconst hasLarkDefinition = typeof larkDefinition === \"string\" && larkDefinition.trim().length > 0;\n\tconst hasRegexDefinition = typeof regexDefinition === \"string\" && regexDefinition.trim().length > 0;\n\tif (!hasLarkDefinition && !hasRegexDefinition) {\n\t\tthrow new Error(\n\t\t\t`Tool \"${tool.name}\" cannot use grammar constrained sampling: no supported grammar variant was provided.`,\n\t\t);\n\t}\n\n\ttry {\n\t\treturn {\n\t\t\tformat: hasLarkDefinition ? \"lark\" : \"regex\",\n\t\t\tdefinition: hasLarkDefinition ? larkDefinition : regexDefinition!,\n\t\t\tinputProperty: inferGrammarInputProperty(tool),\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.`);\n\t}\n}\n\nexport function createGrammarToolInputProperties(\n\ttools: Tool[] | undefined,\n\tsupportsOpenAIGrammarTools: boolean,\n): ReadonlyMap<string, string> {\n\tconst properties = new Map<string, string>();\n\tfor (const tool of tools ?? []) {\n\t\tconst grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);\n\t\tif (grammar) {\n\t\t\tproperties.set(tool.name, grammar.inputProperty);\n\t\t}\n\t}\n\treturn properties;\n}\n","sourceCodeStart":243,"sourceCodeEnd":278,"githubUrl":"https://github.com/earendil-works/pi/blob/4af9d21d3b4d664e4a29fcabfec85171077248e3/packages/ai/src/api/constrained-sampling.ts#L243-L278","documentation":"Error \"Tool \"${tool.name}\" cannot use grammar constrained sampling: ${message}.\" thrown in earendil-works/pi.","triggerScenarios":"Thrown at packages/ai/src/api/constrained-sampling.ts:261 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Address the embedded message: adjust the tool schema or the grammar configuration."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4af9d21d3b4d664e4a29fcabfec85171077248e3","analyzedAt":"2026-08-24T13:07:14.692Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}