Skip to content
Latchkey

Semgrep "Invalid rule schema" / "Invalid YAML" in CI

Semgrep validates rule files before scanning. A YAML syntax error, or a rule missing a required key (id, pattern, message, severity, languages), makes Semgrep reject the config and stop before analysis.

What this error means

Semgrep fails with "Invalid rule schema" or "Invalid YAML file" naming the rule file and the missing or wrong field.

Semgrep
Invalid rule schema at rules/custom.yaml:
  rules.0: 'message' is a required property
Invalid YAML file: rules/custom.yaml

Common causes

A required rule field is missing

Custom rules must include id, message, severity, languages, and a pattern; omitting one fails schema validation.

YAML syntax errors in the rule file

Bad indentation, tabs, or an unquoted special character make the file unparseable.

How to fix it

Validate the rule file

  1. Run semgrep --validate against the rule directory.
  2. Add the missing required field the error names.
  3. Fix YAML indentation and quoting, then re-run.
Terminal
semgrep --validate --config rules/

Use a complete rule template

Ensure each rule has all required keys before committing.

rules/custom.yaml
rules:
  - id: no-eval
    pattern: eval(...)
    message: Avoid eval on untrusted input
    severity: ERROR
    languages: [python]

How to prevent it

  • Run semgrep --validate in CI or pre-commit for rule changes.
  • Keep a rule template with all required fields.
  • Lint YAML to catch indentation and quoting errors early.

Frequently asked questions

What causes ""Invalid rule schema" / "Invalid YAML""?
Custom rules must include id, message, severity, languages, and a pattern; omitting one fails schema validation.
How do I fix "Invalid rule schema" / "Invalid YAML"?
Validate the rule file

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card