Skip to content

fix: add type guard in process_config for non-dict input#4618

Open
Anandesh-Sharma wants to merge 1 commit intocrewAIInc:mainfrom
Anandesh-Sharma:fix/4419-process-config-type-guard
Open

fix: add type guard in process_config for non-dict input#4618
Anandesh-Sharma wants to merge 1 commit intocrewAIInc:mainfrom
Anandesh-Sharma:fix/4419-process-config-type-guard

Conversation

@Anandesh-Sharma
Copy link

Summary

  • Adds a type guard at the start of process_config() to handle non-dict input gracefully
  • When Task(agent="string") is passed, Pydantic's mode='before' validator forwards the raw string to process_config(), which calls .get() on it, causing an AttributeError
  • The fix returns non-dict values unchanged, allowing Pydantic's type validation to produce a proper ValidationError

Fixes #4419

Test plan

  • Verify Task(agent="string") raises a clear Pydantic ValidationError instead of AttributeError
  • Verify normal dict-based config processing still works correctly
  • Verify Task(agent=Agent(...)) continues to work as expected

🤖 Generated with Claude Code

When Pydantic's `mode='before'` validator passes raw input to
`process_config`, the `values` parameter may not be a dict (e.g., when
`Task(agent="string")` is used). This causes an `AttributeError` on
`values.get()`. Adding a type guard returns non-dict values unchanged,
letting Pydantic's own type validation produce a proper ValidationError.

Fixes crewAIInc#4419

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Task(agent=...) with non-Agent type crashes with AttributeError instead of validation error

1 participant