Skip to content

Conversation

deepakstwt
Copy link
Contributor

Bug Fix: Handle None Response in Evaluator

Problem Description

When the Evaluator receives a None response from extract_json_from_response, it currently lacks proper error handling, leading to TypeError crashes during runtime. This issue affects the stability of the application, especially when processing malformed JSON responses from LLM.

Root Cause Analysis

The absence of a null check for extract_json_from_response return value allows json.loads(None) to be called, which raises TypeError: the JSON object must be str, bytes or bytearray, not NoneType.

Solution Description

  • Implemented a validation check to detect None responses from extract_json_from_response
  • Added appropriate error handling to gracefully manage such cases with descriptive error messages
  • Improved logging by changing logger.error to logger.debug for prompt response logging

Code Changes

File: evaluator.py (lines 80-87)

# Before (crashes on None)
response_text = extract_json_from_response(response_text)
evaluation_dict = json.loads(response_text)  # ← TypeError if response_text is None

# After (proper handling)
response_text = extract_json_from_response(response_text)
if response_text is None:
    logger.error("❌ Failed to extract valid JSON from LLM response")
    raise ValueError("Invalid JSON response from LLM")
evaluation_dict = json.loads(response_text)  # ← Safe to call now

Verification Steps

  1. ✅ Tested scenarios where extract_json_from_response returns None
  2. ✅ Confirmed application handles these cases without crashing
  3. ✅ Verified proper error messages are logged
  4. ✅ Ensured existing functionality remains intact

Affected Areas

  • evaluator.py module: Updated to include None response handling
  • Error handling: Improved with descriptive error messages
  • Logging: Better debug information for troubleshooting

Impact

  • Prevents crashes when LLM returns malformed JSON
  • Improves stability of resume evaluation system
  • Better error messages for debugging and troubleshooting
  • Graceful error handling instead of unhandled exceptions

Testing

  • Unit tests for None response scenarios
  • Verified proper ValueError is raised with descriptive message
  • Confirmed valid JSON responses still work correctly
  • No regression in existing functionality

References

Checklist

  • Implemented error handling for None responses in Evaluator
  • Added descriptive error messages and logging
  • Verified that all existing tests pass
  • Tested both failure and success scenarios
  • No linting errors introduced

- Add null check for extract_json_from_response return value
- Raise ValueError with descriptive message when response is None
- Change logger.error to logger.debug for prompt response logging
- Prevent TypeError when json.loads() receives None value

This fixes the crash that occurred when LLM returns malformed JSON
and extract_json_from_response returns None.

Fixes #[ISSUE_NUMBER]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Missing error handling for None response in evaluator.py causing crashes

1 participant