JuliusBrussee/caveman · error · Error
: unsupported or missing $schema
Error message
${file}: unsupported or missing $schema What it means
Every schema file must declare $schema as exactly the JSON Schema 2020-12 meta-schema URI, because the script compiles schemas with Ajv2020. A schema with a missing $schema, an older draft (draft-07, 2019-09), or a typo'd URI makes the file unsupported and throws this error naming the offending file.
Solutions
- Set "$schema": "https://json-schema.org/draft/2020-12/schema" at the top level of the named schema file
- If the schema uses draft-07 features, port it to 2020-12 instead of downgrading the script's Ajv
- Check for trailing whitespace/typos in the $schema URI string
- Regenerate the schema from the contract toolchain configured for 2020-12
Example fix
// before
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://caveman.so/schemas/adapter-conformance.schema.json"
}
// after
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://caveman.so/schemas/adapter-conformance.schema.json"
} Defensive patterns
Strategy: validation
Validate before calling
const REQUIRED = 'https://json-schema.org/draft/2020-12/schema';
for (const f of files) {
const s = JSON.parse(await readFile(path.join(schemaRoot, f), 'utf8'));
if (s.$schema !== REQUIRED) throw new Error(`${f}: $schema must be ${REQUIRED}`);
} Type guard
const isDraft2020 = (s) => typeof s?.$schema === 'string' && s.$schema === 'https://json-schema.org/draft/2020-12/schema';
Try / catch
try { loadSchemas(); } catch (e) { if (e.message.includes('unsupported or missing $schema')) { console.error('Port schema to draft 2020-12:', e.message); process.exitCode = 1; } else throw e; } Prevention
- Copy schemas only from 2020-12-based projects or port them on import
- Add a pre-commit hook that checks $schema in every schema file
- Use an editor schema template with the meta-schema prefilled
When it happens
Trigger: Running scripts/validate-schemas.mjs when a file in schemas/*.schema.json has schema.$schema !== "https://json-schema.org/draft/2020-12/schema" — typically a draft-07 schema copied from another project or a missing top-level $schema key.
Common situations: Copy-pasting a schema from a project using draft-07 and ajv (not Ajv2020); a schema authoring tool emitting an older meta-schema; hand-written schemas omitting $schema entirely.
Related errors
- adapter conformance schema failed to compile
- : missing $id
- schema failed to compile
- canonical span
- caveman agent: Standard Schema cannot emit draft-07 input…
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/97c43d7910f17f68.
Report an issue: GitHub.
Appendix: source
Thrown at packages/shared/contracts/scripts/validate-schemas.mjs:20
import { fileURLToPath } from "node:url";
import path from "node:path";
import Ajv2020 from "ajv/dist/2020.js";
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const schemaRoot = path.join(packageRoot, "schemas");
const files = (await readdir(schemaRoot))
.filter((name) => name.endsWith(".schema.json"))
.sort();
if (files.length === 0) {
throw new Error("no JSON schemas found");
}
const schemas = [];
for (const file of files) {
const schema = JSON.parse(await readFile(path.join(schemaRoot, file), "utf8"));
if (schema.$schema !== "https://json-schema.org/draft/2020-12/schema") {
throw new Error(`${file}: unsupported or missing $schema`);
}
if (typeof schema.$id !== "string" || schema.$id.length === 0) {
throw new Error(`${file}: missing $id`);
}
schemas.push(schema);
}
const ajv = new Ajv2020({ allErrors: true, strict: true });
ajv.addSchema(schemas);
for (const schema of schemas) {
const validate = ajv.getSchema(schema.$id);
if (!validate) throw new Error(`schema failed to compile: ${schema.$id}`);
}
const agentFixtureRoot = path.join(packageRoot, "fixtures", "agent");
const fixtureFiles = (await readdir(agentFixtureRoot))
.filter((name) => name.endsWith(".json"))
.sort();View on GitHub (pinned to 3ee70a1026)