[BUG] structured output validation crashes on None or dict content
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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