ory/kratos · error

Could not compile the identity schema. This is an error…

Error message

Could not compile the identity schema. This is an error with the binary you use and should be reported. Thanks ;)

What it means

ValidateIdentity compiles the swagger payload definition for identity creation into a JSON schema compiler. If swagger.New or the compiler's AddSchema step fails, the earlier wrapped error is returned; if the subsequent Compile of the create-identity path fails, this error wraps it. The message explicitly states this is an internal bug in the binary (broken embedded schema), not a user configuration problem, and asks that it be reported.

Solutions

  1. Rebuild or re-download the binary — a fresh official release usually resolves it.
  2. Check the underlying wrapped error in the output for the exact compiler failure.
  3. Upgrade to the latest version of the CLI in case the embedded schema was fixed upstream.
  4. Report the issue to the project maintainers with the full error output and binary version.

Example fix

// before: patched/broken binary
./identities validate --schema ./identity.traits.schema.json
// after: reinstall official release
curl -sSL https://get.ory.sh/kratos | bash -s --
./identities validate --schema ./identity.traits.schema.json
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

null

Try / catch

err := identities.ValidateIdentity(cmd, args)
if err != nil {
    if strings.Contains(err.Error(), "Could not compile the identity schema") {
        // internal binary bug: report with version, suggest reinstall
        fmt.Fprintln(os.Stderr, "binary defect detected; reinstall or upgrade the CLI")
    }
    return err
}

Prevention

When it happens

Trigger: Running `identities validate` when the embedded swagger identity schema cannot be added to or compiled by the JSON schema compiler — e.g. the schema embedded at build time is malformed, or the schema compiler rejects the swagger definition URL/path createIdentityPath.

Common situations: Corrupted or partially-built binary, a release where the embedded identity.traits schema JSON was invalid, or an incompatible schema compiler version choking on the swagger output. End users essentially never cause this via configuration.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07). Data as JSON: /api/errors/841c24efe3d5e2cd. Report an issue: GitHub.

Appendix: source

Thrown at cmd/identities/validate.go:96

type SchemaGetter = func(ctx context.Context, id string) (map[string]interface{}, *http.Response, error)

// ValidateIdentity validates the json payload fc against
// 1. the swagger payload definition and
// 2. the remote custom identity schema.
func ValidateIdentity(cmd *cobra.Command, src, i string, getRemoteSchema SchemaGetter) error {
	swaggerSchema, ok := schemas[createIdentityPath]
	if !ok {
		// add swagger schema
		schemaCompiler := jsonschema.NewCompiler()
		err := schemaCompiler.AddResource("api.json", bytes.NewReader(spec.API))
		if err != nil {
			return errors.Wrap(err, "Could not add swagger schema to the schema compiler. This is an error with the binary you use and should be reported. Thanks ;)")
		}

		// compile swagger payload definition
		swaggerSchema, err = schemaCompiler.Compile(cmd.Context(), createIdentityPath)
		if err != nil {
			return errors.Wrap(err, "Could not compile the identity schema. This is an error with the binary you use and should be reported. Thanks ;)")
		}
		// force additional properties to false because swagger does not render this
		swaggerSchema.AdditionalProperties = false
		schemas[createIdentityPath] = swaggerSchema
	}

	// validate against swagger definition
	var foundValidationErrors bool
	err := swaggerSchema.Validate(bytes.NewBufferString(i))
	if err != nil {
		_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s: not valid\n", src)
		jsonschemax.FormatValidationErrorForCLI(cmd.ErrOrStderr(), []byte(i), err)
		foundValidationErrors = true
	}

	// get custom identity schema id
	sid := gjson.Get(i, "schema_id")
	if !sid.Exists() {

View on GitHub (pinned to b86338da04)