YAML Validation

Catch duplicate agent/task names and unknown task→agent references before an agent starts

Duplicate agent names or a typo in task.agent used to collapse your YAML silently — a 3-agent config could run as 1. Now you get a warning by default, and an exception under PRAISONAI_VALIDATE_STRICT=true.

Diagram

clean

duplicate name

unknown task agent

📄 agents.yaml

🔍 Validate

✅ Run

⚠️ Warn / Raise

⚠️ Warn / Raise

Why this exists

Before this validation existed, a YAML with a duplicate name: researcher on two agents ran as one agent — the second silently overwrote the first via a dict-merge collapse. A task typo like agent: reseacher (missing an r) skipped the task with no message. Both problems look like a broken run with no clear cause.

PRAISONAI_VALIDATE_STRICT=true turns those silent collapses into loud failures. In CI, prefer strict. In development, the default warning gives you the same hint without stopping the session.

Strictness resolves in this order:

strict_validation:
  explicit arg  >  cli_config["strict_validation"]  >  PRAISONAI_VALIDATE_STRICT env  >  False (default)

Quick Start

  1. Default (warn)

    A duplicate name: no longer overwrites the first agent — both are kept under suffixed keys and you get a warning.

    yaml
    agents:
      - name: researcher
        instructions: "Research the topic"
      - name: researcher
        instructions: "Different researcher, same name"
    WARNING  Duplicate agent name(s) in YAML: ['researcher'] — kept both by suffixing keys; rename to silence.

    Both entries survive; the colliding one is preserved under researcher__dup_1 (0-based list index).

  2. Strict (CI)

    Turn the warning into a hard failure so CI catches the config before an agent starts.

    bash
    export PRAISONAI_VALIDATE_STRICT=true
    python
    ValueError: Duplicate agent name(s) in YAML: ['researcher']
  3. Unknown task agent

    A task whose agent: doesn’t match any defined agent warns by default, raises under strict.

    yaml
    agents:
      - name: researcher
        instructions: "Research the topic"
    
    tasks:
      - name: draft_report
        agent: reseacher   # typo: missing an 'r'
        description: "Draft the report"
    WARNING  Task 'draft_report' references unknown agent 'reseacher'; skipping.

    Under PRAISONAI_VALIDATE_STRICT=true:

    python
    ValueError: Task 'draft_report' references unknown agent 'reseacher'; skipping.

How It Works

Diagram
Runduplicate / task-ref check_normalize_yaml_configPraisonAI CLIRunduplicate / task-ref check_normalize_yaml_configPraisonAI CLIalt[clean][issue found (default)][issue found (strict)]load agents.yamlcheck names & task→agent refsrunlogger.warning(…)run (both entries kept)raise ValueError
CheckTriggerDefaultPRAISONAI_VALIDATE_STRICT=true
Duplicate agent nameSame name: in agents: listWarn + keep both via __dup_iRaise ValueError
Duplicate role nameSame name: in roles: listWarn + keep both via __dup_iRaise ValueError
Unknown task agenttask.agent matches no agentWarn + skip taskRaise ValueError
Unknown top-level / agent fieldKey not in schemaWarn + ignore fieldRe-emitted as a [strict mode] error by ConfigValidator

When both roles: and agents: are present, roles: wins for task→agent resolution.


Unknown-field warnings

Any YAML key the schema doesn’t declare is flagged, then ignored — so a typo like instrucions: doesn’t silently drop your instructions.

yaml
foo: bar                 # unknown top-level key

agents:
  myagent:
    role: Researcher
    goal: Find facts
    instructions: "Research the topic"
    bar: baz             # unknown agent key
Unknown top-level field 'foo'. This field will be ignored.
agents.myagent: Unknown field 'bar'. This field will be ignored.

The field lists are derived from the Pydantic schema, not hand-maintained:

  • Top-level keys are checked against YAMLConfig.model_fields.
  • Agent-block keys are checked against AgentConfig.model_fields | {"name"}.

Adding a field to YAMLConfig or AgentConfig automatically teaches the validator — there is no second list to edit. This is why type, deploy, and dependencies (added to YAMLConfig in PraisonAI PR #4651) stopped warning the moment they were declared on the schema.


Choosing a mode

Diagram

Local development

CI / production

Where does this YAML run?

Default (warn)
keep iterating

PRAISONAI_VALIDATE_STRICT=true
fail fast


Configuration

PRAISONAI_VALIDATE_STRICT controls whether validation issues warn or raise.

VariableValuesEffect
PRAISONAI_VALIDATE_STRICT"true" (case-insensitive) → strict; anything else (unset, "1", "yes", "on", "") → non-strictUnder strict, YAML validation issues raise ValueError instead of warning. Default is non-strict.
bash
# Strict — raise on any validation issue
export PRAISONAI_VALIDATE_STRICT=true

# Non-strict (default) — warn only. These all count as non-strict:
export PRAISONAI_VALIDATE_STRICT=1     # ⚠️ still non-strict
export PRAISONAI_VALIDATE_STRICT=yes   # ⚠️ still non-strict
unset PRAISONAI_VALIDATE_STRICT        # non-strict

Duplicate-preserved key naming

Under the default (warn) mode, colliding entries are kept — not dropped. The duplicate is stored under a suffixed key so both survive:

{name}__dup_{i}

i is the 0-based list index of the colliding entry. A second agent named researcher at list index 1 becomes researcher__dup_1.

Grep-friendly messages

Copy these into your CI log filters:

Duplicate agent name(s) in YAML: ['researcher'] — kept both by suffixing keys; rename to silence.
Task 'draft_report' references unknown agent 'reseacher'; skipping.

Under PRAISONAI_VALIDATE_STRICT=true the same conditions raise:

ValueError: Duplicate agent name(s) in YAML: ['researcher']
ValueError: Task 'draft_report' references unknown agent 'reseacher'; skipping.

Best Practices

Turn on strict mode in CI

Set PRAISONAI_VALIDATE_STRICT=true in your CI environment so a duplicate name or a task typo fails the pipeline instead of silently degrading a run. Keep the default (warn) locally so quick experiments aren’t blocked.

Set true, not 1

This variable only recognises the literal string "true" (case-insensitive). PRAISONAI_VALIDATE_STRICT=1 looks enabled but behaves as non-strict. Always use =true.

Rename duplicates instead of relying on the suffix

The __dup_i suffix keeps both entries so nothing is silently lost, but a name collision is almost always a mistake. Rename the second agent to silence the warning and make the config unambiguous.

Fix task→agent typos at the source

An unknown agent: on a task means that task never runs. Match the agent: value exactly to a defined agent name — under strict mode the run stops until you do.


Related