Skip to content

fix: guard against empty choices and message=None in LLM responses (2 files)#233

Open
qizwiz wants to merge 1 commit into
microsoft:mainfrom
qizwiz:fix/guard-empty-choices-llm-response
Open

fix: guard against empty choices and message=None in LLM responses (2 files)#233
qizwiz wants to merge 1 commit into
microsoft:mainfrom
qizwiz:fix/guard-empty-choices-llm-response

Conversation

@qizwiz

@qizwiz qizwiz commented May 18, 2026

Copy link
Copy Markdown

What

Guards response.choices[0] in two flow utility files before accessing .message.content:

chat_with_pdf/flows/standard/chat_with_pdf/utils/oai.py (OAI.stream method):

+ if not response.choices or response.choices[0].message is None:
+     raise ValueError("LLM returned empty or filtered response")
  return response.choices[0].message.content

function_flows/flows/basic/llm.py (my_llm_tool function):

+ if not response.choices or response.choices[0].message is None:
+     raise ValueError("LLM returned empty or filtered response")
  return response.choices[0].message.content

Why

The OpenAI API (and Azure OpenAI) can return choices=[] or choices[0].message=None at HTTP 200 when content is filtered by safety systems. Without the guard, promptflow pipelines receive an IndexError/AttributeError that terminates the flow run without a meaningful error message.

Azure content filtering is particularly common in enterprise deployments — this is a real failure mode for promptflow users.

Evidence

Scope

2 files, 4 lines added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant