crewAIInc/crewAI · error · SystemExit
Invalid input '{location}': {error.get('msg')}
Error message
Invalid input '{location}': {error.get('msg')} What it means
Pydantic validation of flow state inputs failed: state_model.model_validate(values) raised a ValidationError, and the CLI prints one red line per error with the dotted location path (error['loc']) and message (error['msg']) before exiting 1. This fires after missing-input checks pass, so the values exist but have the wrong type or violate field constraints.
Source
Thrown at lib/cli/src/crewai_cli/run_declarative_flow.py:378
return [
str(error["loc"][0])
for error in exc.errors()
if error.get("type") == "missing" and error.get("loc")
]
return []
def _validate_flow_inputs(state_model: Any, values: dict[str, Any]) -> None:
"""Validate inputs against the state schema; exit with pointed type errors."""
try:
state_model.model_validate(values)
except ValidationError as exc:
for error in exc.errors():
location = ".".join(str(part) for part in error.get("loc", ()))
click.secho(
f" Invalid input '{location}': {error.get('msg')}", fg="red", err=True
)
raise SystemExit(1) from exc
def _coerce_input(raw: str, spec: dict[str, Any]) -> Any:
"""Best-effort coerce a prompted string to the field's JSON-schema type."""
field_type = spec.get("type")
if field_type == "integer":
try:
return int(raw)
except ValueError:
return raw
if field_type == "number":
try:
return float(raw)
except ValueError:
return raw
if field_type == "boolean":
return raw.strip().lower() in {"1", "true", "yes", "y", "on"}
return rawView on GitHub (pinned to 754d7323be)
Solutions
- Fix the value at the printed location to match the state model's declared type (e.g. send 42, not "42", for int fields).
- If the value legitimately arrives as a string, add coercion in the state model (pydantic validators or use a coercing type) since _coerce_input only handles integer/number best-effort.
- For nested locations like 'a.b.0', check the corresponding nested model/list element.
- Validate inputs locally first: FlowState.model_validate(inputs) in a scratch script.
Example fix
# before
# state: max_items: int
$ crewai flow run --inputs '{"max_items": "ten"}'
# Invalid input 'max_items': Input should be a valid integer ...
# after
$ crewai flow run --inputs '{"max_items": 10}' Defensive patterns
Strategy: type-guard
Validate before calling
from pydantic import ValidationError
try:
StateModel.model_validate(inputs)
except ValidationError as exc:
for err in exc.errors():
print("fix:", err["loc"], err["msg"])
raise SystemExit(1) Type guard
def inputs_match_state(state_model: type, values: dict) -> bool:
"""True when values already satisfy the flow's state schema."""
try:
state_model.model_validate(values)
return True
except ValidationError:
return False Try / catch
from pydantic import ValidationError
try:
state_model.model_validate(values)
except ValidationError as exc:
# print loc + msg per error, mirroring the CLI, then fix data not code
details = "\n".join(f"{'.'.join(map(str, e['loc']))}: {e['msg']}" for e in exc.errors())
raise SystemExit(f"invalid flow inputs:
{details}") from exc Prevention
- Never assume string→number coercion: send real JSON numbers for int/float state fields.
- Reuse the flow's pydantic state model as the source of truth for input forms and API payloads.
- Add pydantic validators (e.g. BeforeValidator) for fields fed from string-only sources like env vars.
When it happens
Trigger: Passing a string where the state model declares int/float/list (common when inputs come from CLI/env and _coerce_input's best-effort coercion fails — e.g. 'abc' for an integer field stays a string); enum/literal mismatches; constraint violations (gt/le, pattern); nested dict structures not matching nested models.
Common situations: Shell-sourced inputs that are always strings; JSON inputs files written by hand with quoted numbers; API responses feeding flow inputs with inconsistent types.
Related errors
- Missing required input '{name}'{suffix}
- Invalid --inputs JSON: {exc}
- Invalid --inputs JSON: expected an object.
- Missing required input '{name}'
- Invalid --definition path: {definition} is not a file.
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/cb042a2fb51ba978.
Report an issue: GitHub.