Debug Fix easy · 3 min read

Fix NeMo Guardrails colang syntax error

Quick answer
A colang syntax error in NeMo Guardrails typically occurs due to incorrect indentation, missing colons, or improper block structure in the guardrail script. Fix the syntax by ensuring proper YAML-like indentation, correct use of colons, and valid colang constructs as per the Guardrails documentation.
ERROR TYPE code_error
⚡ QUICK FIX
Correct the colang script indentation and syntax by following Guardrails' YAML-based formatting rules precisely.

Why this happens

The colang syntax error arises when the NeMo Guardrails script violates YAML or Guardrails-specific formatting rules. Common triggers include inconsistent indentation, missing colons after keys, or invalid block structures in the colang script. For example, a guardrail block missing a colon or having mixed spaces and tabs will cause a parsing failure and syntax error.

Example of broken colang snippet causing syntax error:

guardrails:
  - name: example_guardrail
    prompt: |
      What is your name?
    rules
      - role: user
        pattern: .*

This snippet misses a colon after rules and has indentation issues, triggering the syntax error.

yaml
guardrails:
  - name: example_guardrail
    prompt: |
      What is your name?
    rules
      - role: user
        pattern: .*
output
SyntaxError: expected ':' after key 'rules' at line 6

The fix

Fix the colang syntax error by ensuring all keys have colons, indentation is consistent (usually 2 spaces), and block structures follow YAML conventions. The rules key must be followed by a colon, and list items properly indented.

Corrected colang snippet:

yaml
guardrails:
  - name: example_guardrail
    prompt: |
      What is your name?
    rules:
      - role: user
        pattern: ".*"
output
Parsed successfully without syntax errors

Preventing it in production

To avoid colang syntax errors in production, always validate your guardrail scripts with a YAML linter or the Guardrails CLI validation tool before deployment. Use consistent indentation (spaces, not tabs), and ensure all keys end with colons. Implement automated tests that load and parse your guardrails to catch syntax issues early.

Additionally, maintain version control on your guardrail scripts and review changes carefully to prevent accidental formatting errors.

Key Takeaways

  • Always use consistent 2-space indentation and colons after keys in colang scripts.
  • Validate guardrail scripts with YAML linters or Guardrails CLI before deployment.
  • Automate syntax checks in CI/CD pipelines to catch errors early and prevent runtime failures.
Verified 2026-04
Verify ↗