crewAIInc/crewAI · error · Exception
An error occurred while running the crew: {e}
Error message
An error occurred while running the crew: {e} What it means
This is a catch-all wrapper in the generated crew project template (main.py). Any exception raised during {{crew_name}}().crew().kickoff(inputs) — LLM auth failures, missing API keys, task agent errors — is re-raised as a generic Exception with the message 'An error occurred while running the crew: {e}'. The original exception is chained implicitly but its type is lost, so callers cannot catch specific failure modes.
Source
Thrown at lib/cli/src/crewai_cli/templates/crew/main.py:24
from {{folder_name}}.crew import {{crew_name}}
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd")
def run():
"""
Run the crew.
"""
inputs = {
'topic': 'AI LLMs',
'current_year': str(datetime.now().year)
}
try:
{{crew_name}}().crew().kickoff(inputs=inputs)
except Exception as e:
raise Exception(f"An error occurred while running the crew: {e}")
def train():
"""
Train the crew for a given number of iterations.
"""
inputs = {
"topic": "AI LLMs",
'current_year': str(datetime.now().year)
}
try:
{{crew_name}}().crew().train(n_iterations=int(sys.argv[1]), filename=sys.argv[2], inputs=inputs)
except Exception as e:
raise Exception(f"An error occurred while training the crew: {e}")
def replay():
"""View on GitHub (pinned to 754d7323be)
Solutions
- Read the text after the colon — it contains the original exception's str(); fix that underlying error (most often a missing API key in .env).
- Re-run with the inner traceback visible: temporarily replace the except block with `except Exception: import traceback; traceback.print_exc(); raise` or just remove the try/except in your local main.py.
- Verify all env vars listed in .env.example are set (OPENAI_API_KEY, SERPER_API_KEY, etc.) before kickoff.
- Validate config files (config/agents.yaml, config/tasks.yaml) reference agents/tasks consistently and all tools import cleanly.
Example fix
# before
try:
MyCrew().crew().kickoff(inputs=inputs)
except Exception as e:
raise Exception(f"An error occurred while running the crew: {e}")
# after
try:
MyCrew().crew().kickoff(inputs=inputs)
except Exception:
import traceback
traceback.print_exc()
raise Defensive patterns
Strategy: try-catch
Validate before calling
import os
required = ["OPENAI_API_KEY"]
missing = [k for k in required if not os.getenv(k)]
if missing:
raise SystemExit(f"Missing env vars: {missing}") Try / catch
try:
result = MyCrew().crew().kickoff(inputs=inputs)
except Exception as e:
# inspect e.__cause__ / full text — wrapper loses the original type
logging.exception("crew kickoff failed")
raise Prevention
- Populate .env from .env.example before first run
- Smoke-test kickoff in a scratch script without the template wrapper so tracebacks stay intact
- Wrap scheduled runs with logging that captures the full traceback, not just str(e)
When it happens
Trigger: Running `crewai run` (or `uv run run`) on a scaffolded crew where kickoff() fails: missing OPENAI_API_KEY, invalid model name, misconfigured agent/backstory YAML, tool import errors in crewai_agents_config, or an LLM rate limit during the first task.
Common situations: Freshly scaffolded project where .env is not populated; YAML config referencing a non-existent agent key; model provider env var misspelled; network outage mid-kickoff. The generic message hides the root cause, so developers paste the whole wrapper message into searches instead of the inner error.
Related errors
- An error occurred while running the crew with trigger: {e}
- An error occurred while running the flow with trigger: {e}
- An error occurred while training the crew: {e}
- An error occurred while replaying the crew: {e}
- An error occurred while testing the crew: {e}
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/810aae5b7a687da7.
Report an issue: GitHub.