crewAIInc/crewAI · error · SystemExit

Invalid --inputs JSON: {exc}

Error message

Invalid --inputs JSON: {exc}

What it means

Emitted by parse_inputs_json when the --inputs CLI option contains text that json.loads cannot parse (JSONDecodeError), after which the CLI exits with code 1. The message echoes the decoder's precise reason (line/column, e.g. 'Expecting value: line 1 column 1'). This guards the structured inputs passed to crew/flow run commands before any execution starts.

Source

Thrown at lib/cli/src/crewai_cli/input_prompt.py:33

import json
import sys
from typing import Any

import click

from crewai_cli.utils import enable_prompt_line_editing, is_dmn_mode_enabled


def parse_inputs_json(inputs: str | None) -> dict[str, Any] | None:
    """Parse a ``--inputs`` JSON object, exiting with a pointed error if invalid."""
    if inputs is None:
        return None

    try:
        parsed = json.loads(inputs)
    except json.JSONDecodeError as exc:
        click.echo(f"Invalid --inputs JSON: {exc}", err=True)
        raise SystemExit(1) from exc

    if not isinstance(parsed, dict):
        click.echo("Invalid --inputs JSON: expected an object.", err=True)
        raise SystemExit(1)

    return parsed


def closest_name(key: str, candidates: Iterable[str]) -> str | None:
    """Nearest candidate name to a likely typo, if one is close enough."""
    matches = difflib.get_close_matches(key, list(candidates), n=1, cutoff=0.7)
    return matches[0] if matches else None


def is_interactive() -> bool:
    """Prompt only in an interactive terminal, never in non-interactive mode."""
    return not is_dmn_mode_enabled() and sys.stdin.isatty()

View on GitHub (pinned to 754d7323be)

Solutions

  1. Use strict double-quoted JSON: `--inputs "{\"topic\": \"AI\"}"` or single-quote the whole arg on POSIX: `--inputs '{"topic": "AI"}'`
  2. Validate first: `echo '<your json>' | python -m json.tool` to localize the syntax error (the message already gives line/column)
  3. Replace smart/curly quotes with straight quotes
  4. On Windows, escape inner double quotes or pass via a file if the CLI supports it

Example fix

# before
crewai run --inputs "{'topic': 'AI agents'}"
# after
crewai run --inputs '{"topic": "AI agents"}'
Defensive patterns

Strategy: validation

Validate before calling

import json

def inputs_json_valid(s: str | None) -> bool:
    if s is None:
        return True
    try:
        return isinstance(json.loads(s), dict)
    except json.JSONDecodeError:
        return False

Type guard

def parse_inputs(s: str) -> dict | None:
    import json
    try:
        v = json.loads(s)
    except json.JSONDecodeError:
        return None
    return v if isinstance(v, dict) else None

Try / catch

try:
    parse_inputs_json(raw)
except SystemExit as e:
    if e.code == 1:
        # invalid --inputs JSON; re-prompt or show expected shape
        ...

Prevention

When it happens

Trigger: Passing `crewai run --inputs "{'topic': 'x'}"` (single quotes = invalid JSON), an unterminated string, trailing commas, smart quotes pasted from a doc, or a shell that mangles the quoting so an empty/partial string reaches the parser.

Common situations: Single-quoted Python-style dicts pasted into shell, copy-paste from editors that substitute curly quotes, forgetting to close a quote so shell splits the JSON, or Windows cmd quoting differences around double quotes.

Related errors


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