Bug: provider does not handle null message content / finish_reason, crashing with 'NoneType' object has no attribute 'strip'

Author: rajarshidattapyCreated Sep 12, 2026Updated Sep 12, 2026

Description

OpenAICompatibleProvider.chat returns choices[0].message.content without checking whether it is None or whether finish_reason indicates the output is unusable:

https://github.com/interviewstreet/hiring-agent/blob/70fd3ea/models.py#L374-L379

OpenAI-compatible APIs return "content": null in several normal situations (e.g. safety/content-filter blocks, some refusals, reasoning models that exhaust the token budget), and return truncated JSON when finish_reason == "length".

The None then flows into extract_json_from_response, which immediately calls .strip():

https://github.com/interviewstreet/hiring-agent/blob/70fd3ea/llm_utils.py#L24

Actual

python
from llm_utils import extract_json_from_response
extract_json_from_response(None)
# AttributeError: 'NoneType' object has no attribute 'strip'
  • In pdf.py this is swallowed as ❌ Error calling LLM for basics section: 'NoneType' object has no attribute 'strip', retried once, and extraction aborts.
  • In evaluator.py it propagates as an unhandled traceback.

Neither message tells the user the model returned no content or why.

Expected

The provider raises a clear error such as ValueError("Empty response from <url> (finish_reason=content_filter)"), and a finish_reason of length is reported as truncation rather than surfacing later as a JSON decode error.

Source: interviewstreet/hiring-agent