crewAIInc/crewAI · error · Exception

Invalid JSON payload provided as argument

Error message

Invalid JSON payload provided as argument

What it means

Raised by run_with_trigger() in the crew template when sys.argv[1] cannot be parsed by json.loads. It is a strict input validation error: the trigger payload must be a single valid JSON document supplied as the first CLI argument.

Source

Thrown at lib/cli/src/crewai_cli/templates/crew/main.py:78

    try:
        {{crew_name}}().crew().test(n_iterations=int(sys.argv[1]), eval_llm=sys.argv[2], inputs=inputs)

    except Exception as e:
        raise Exception(f"An error occurred while testing the crew: {e}")

def run_with_trigger():
    """
    Run the crew with trigger payload.
    """
    import json

    if len(sys.argv) < 2:
        raise Exception("No trigger payload provided. Please provide JSON payload as argument.")

    try:
        trigger_payload = json.loads(sys.argv[1])
    except json.JSONDecodeError:
        raise Exception("Invalid JSON payload provided as argument")

    inputs = {
        "crewai_trigger_payload": trigger_payload,
        "topic": "",
        "current_year": ""
    }

    try:
        result = {{crew_name}}().crew().kickoff(inputs=inputs)
        return result
    except Exception as e:
        raise Exception(f"An error occurred while running the crew with trigger: {e}")

View on GitHub (pinned to 754d7323be)

Solutions

  1. Validate the payload locally first: `echo '<payload>' | python -m json.tool` to confirm it is valid JSON.
  2. Use single quotes around the whole payload and double quotes inside: `uv run run_with_trigger '{"topic": "AI"}'`.
  3. For long payloads, write to a file and expand via command substitution: `uv run run_with_trigger "$(cat payload.json)"`.
  4. Check for smart quotes or trailing commas introduced by copy-paste.
Defensive patterns

Strategy: validation

Validate before calling

import json, sys
try:
    payload = json.loads(sys.argv[1])
except json.JSONDecodeError as e:
    raise SystemExit(f"Payload is not valid JSON at line {e.lineno} col {e.colno}: {e.msg}")

Type guard

import json
def is_valid_json(text: str) -> bool:
    try:
        json.loads(text)
        return True
    except (json.JSONDecodeError, TypeError):
        return False

Prevention

When it happens

Trigger: Calling `uv run run_with_trigger '{topic: "x"}'` (unquoted keys), passing a file path instead of JSON content, shell-mangled quotes producing broken JSON (e.g. smart quotes from copy-paste), or passing an empty string.

Common situations: Shell quoting mistakes with nested quotes around the JSON; payloads pasted from docs containing non-ASCII quotes; a webhook forwarder that URL-encodes or truncates the body before passing it as argv.

Understand the failure class

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/37fd6b32b2b80e08. Report an issue: GitHub.