Skip to content

Commit 1db7738

Browse files
committed
LCORE-464: fix potential None reference handling
1 parent 6182cd7 commit 1db7738

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/app/endpoints/query.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def is_input_shield(shield: Shield) -> bool:
375375
return _is_inout_shield(shield) or not is_output_shield(shield)
376376

377377

378-
async def retrieve_response( # pylint: disable=too-many-locals
378+
async def retrieve_response( # pylint: disable=too-many-locals,too-many-branches
379379
client: AsyncLlamaStackClient,
380380
model_id: str,
381381
query_request: QueryRequest,
@@ -493,7 +493,18 @@ async def retrieve_response( # pylint: disable=too-many-locals
493493
metrics.llm_calls_validation_errors_total.inc()
494494
break
495495

496-
return str(response.output_message.content), conversation_id # type: ignore[union-attr]
496+
output_message = getattr(response, "output_message", None)
497+
if output_message is not None:
498+
content = getattr(output_message, "content", None)
499+
if content is not None:
500+
return str(content), conversation_id
501+
502+
# fallback
503+
logger.warning(
504+
"Response lacks output_message.content (conversation_id=%s)",
505+
conversation_id,
506+
)
507+
return "", conversation_id
497508

498509

499510
def validate_attachments_metadata(attachments: list[Attachment]) -> None:

0 commit comments

Comments
 (0)