Skip to content

Conversation

@MANYA12-STAR
Copy link

Description

This PR improves the robustness of the SearchApiAPIWrapper by adding null-safe parsing, defensive checks, and a more resilient _result_as_string() extraction flow.

Previously, missing or partially-filled fields returned by SearchAPI (e.g., missing answer_box, absent snippet, empty knowledge_graph, or sparse organic_results) could produce KeyError, inconsistent behavior across engines, or unexpected empty output.

This update introduces:

  • Safe dictionary access via .get() patterns
  • Graceful fallback ordering across all supported response fields
  • Defensive handling for missing or malformed items in arrays
  • Consistent string assembly for organic_results, jobs, videos, and images
  • Improved reliability for both sync and async flows

As a result, the wrapper now behaves predictably across different SearchAPI engines and response variations, avoiding runtime errors while still returning meaningful textual output.

Issue

Closes #338 — Improve SearchApiAPIWrapper to support missing fields and prevent runtime parsing errors.

Dependencies

  • No new dependencies introduced
  • No changes to pyproject.toml
  • All imports remain optional where appropriate

@github-actions github-actions bot added the fix label Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in SearchApiAPIWrapper: Fails to handle missing 'description' in search results

1 participant