earendil-works/pi · error · UnsupportedStrictJsonSchemaError
anyOf must contain at least one schema
Error message
anyOf must contain at least one schema
What it means
An anyOf union that is absent, not an array, or empty cannot be strictened: the converter must recurse into at least one variant to build a valid strict schema. This guard fires on malformed tool schemas where anyOf is declared but carries no members.
Solutions
- Provide at least one subschema in anyOf.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/ai/src/api/constrained-sampling.ts:65 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/6173d873c9391ea7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/ai/src/api/constrained-sampling.ts:65
if (!isJsonSchemaObject(schema)) return false;
if (schema.type === "null" || (Array.isArray(schema.type) && schema.type.includes("null"))) return true;
if (schema.const === null || (Array.isArray(schema.enum) && schema.enum.includes(null))) return true;
return Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));
}
function makeJsonSchemaNodeStrict(schema: unknown): void {
if (!isJsonSchemaObject(schema)) {
throw new UnsupportedStrictJsonSchemaError("boolean schemas are unsupported");
}
for (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {
if (schema[key] !== undefined) {
throw new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);
}
}
if (schema.anyOf !== undefined) {
if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
}
for (const variant of schema.anyOf) {
if (isStructuredSchema(variant)) {
throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
}
makeJsonSchemaNodeStrict(variant);
}
}
if (schema.items !== undefined) {
if (Array.isArray(schema.items)) {
throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
}
makeJsonSchemaNodeStrict(schema.items);
}
const isObjectSchema = schema.type === "object";
if (schema.properties !== undefined && !isObjectSchema) {View on GitHub (pinned to 4af9d21d3b)