Fix: LLM extraction fails when content is in alternative response fields (content_reason, provider_specific_fields.refusal) #1450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes LLM extraction failures when content is returned in alternative response fields instead of the main
contentfield. Some LLM providers (like o1-mini and DeepSeek-V3) occasionally return content incontent_reasonorprovider_specific_fields.refusalfields, causing extraction to fail with "str object has no attribute 'choices'" error.This PR implements a fallback mechanism in the LLM extraction strategy to check multiple response fields when the primary
contentfield is empty or None.Fixes #1449
List of files changed and why
crawl4ai/extraction_strategy.py- Updated LLMExtractionStrategy to implement content extraction fallback mechanismtests/test_extract_response_content.py- Added unit tests to verify fallback behavior with different response structuresHow Has This Been Tested?
content_reasonandprovider_specific_fields.refusalprovider_specific_fields.refusalcontent_reasoncontentfieldChecklist: