crewAIInc / crewAIInc/crewAI

[BUG] structured output validation crashes on None or dict content

Open Beginner friendly
#7,540 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
58.8k
Forks
8.5k
Avg merge
1d 15h
Merged PRs (30d)
109

Description

Description

BaseLLM._validate_structured_output calls response.strip() without checking the type. Native structured output can already be a dict, and some providers pass content=None. Both raise AttributeError before schema validation.

Steps to Reproduce
from pydantic import BaseModel
from crewai.llms.base_llm import BaseLLM

class Out(BaseModel):
    city: str

BaseLLM._validate_structured_output(None, Out)
BaseLLM._validate_structured_output({"city": "London"}, Out)
Expected behavior

None is treated as empty. A dict is validated directly. Strings keep the current JSON parse path.

Screenshots/Code snippets

AttributeError: 'NoneType' object has no attribute 'strip'

Operating System

Windows 11

Python Version

3.12

crewAI Version

main

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at crewai/llms/base_llm.py and inspect BaseLLM._validate_structured_output, then reproduce the None and dict cases from the issue. Done means None is treated as empty, dictionaries are validated directly, and strings retain the current JSON parsing path without AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.