{"record":{"id":"cb042a2fb51ba978","repo":"crewAIInc/crewAI","slug":"invalid-input-location-error-get-msg","errorCode":null,"errorMessage":"Invalid input '{location}': {error.get('msg')}","messagePattern":"Invalid input '(.+?)': (.+?)","errorType":"validation","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"lib/cli/src/crewai_cli/run_declarative_flow.py","lineNumber":378,"sourceCode":"        return [\n            str(error[\"loc\"][0])\n            for error in exc.errors()\n            if error.get(\"type\") == \"missing\" and error.get(\"loc\")\n        ]\n    return []\n\n\ndef _validate_flow_inputs(state_model: Any, values: dict[str, Any]) -> None:\n    \"\"\"Validate inputs against the state schema; exit with pointed type errors.\"\"\"\n    try:\n        state_model.model_validate(values)\n    except ValidationError as exc:\n        for error in exc.errors():\n            location = \".\".join(str(part) for part in error.get(\"loc\", ()))\n            click.secho(\n                f\"  Invalid input '{location}': {error.get('msg')}\", fg=\"red\", err=True\n            )\n        raise SystemExit(1) from exc\n\n\ndef _coerce_input(raw: str, spec: dict[str, Any]) -> Any:\n    \"\"\"Best-effort coerce a prompted string to the field's JSON-schema type.\"\"\"\n    field_type = spec.get(\"type\")\n    if field_type == \"integer\":\n        try:\n            return int(raw)\n        except ValueError:\n            return raw\n    if field_type == \"number\":\n        try:\n            return float(raw)\n        except ValueError:\n            return raw\n    if field_type == \"boolean\":\n        return raw.strip().lower() in {\"1\", \"true\", \"yes\", \"y\", \"on\"}\n    return raw","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/cli/src/crewai_cli/run_declarative_flow.py#L360-L396","documentation":"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.","triggerScenarios":"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.","commonSituations":"Shell-sourced inputs that are always strings; JSON inputs files written by hand with quoted numbers; API responses feeding flow inputs with inconsistent types.","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."],"exampleFix":"# before\n# state: max_items: int\n$ crewai flow run --inputs '{\"max_items\": \"ten\"}'\n#   Invalid input 'max_items': Input should be a valid integer ...\n\n# after\n$ crewai flow run --inputs '{\"max_items\": 10}'","handlingStrategy":"type-guard","validationCode":"from pydantic import ValidationError\n\ntry:\n    StateModel.model_validate(inputs)\nexcept ValidationError as exc:\n    for err in exc.errors():\n        print(\"fix:\", err[\"loc\"], err[\"msg\"])\n    raise SystemExit(1)","typeGuard":"def inputs_match_state(state_model: type, values: dict) -> bool:\n    \"\"\"True when values already satisfy the flow's state schema.\"\"\"\n    try:\n        state_model.model_validate(values)\n        return True\n    except ValidationError:\n        return False","tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    state_model.model_validate(values)\nexcept ValidationError as exc:\n    # print loc + msg per error, mirroring the CLI, then fix data not code\n    details = \"\\n\".join(f\"{'.'.join(map(str, e['loc']))}: {e['msg']}\" for e in exc.errors())\n    raise SystemExit(f\"invalid flow inputs:\n{details}\") from exc","preventionTips":["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."],"tags":["validation","pydantic","flow","type-error","inputs"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}