Skip to content

Fix UnboundLocalError in prompty response formatting when inputs are omitted#47005

Merged
posaninagendra merged 3 commits into
mainfrom
copilot/fix-unbound-local-variable-sample-input
May 20, 2026
Merged

Fix UnboundLocalError in prompty response formatting when inputs are omitted#47005
posaninagendra merged 3 commits into
mainfrom
copilot/fix-unbound-local-variable-sample-input

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

format_llm_response could raise UnboundLocalError by referencing sample_input before assignment when inputs is not provided. This surfaced in async evaluator flows that call prompty without explicit input payloads.

  • Runtime fix in prompty formatting path

    • Initialize sample_input to an empty string before conditional input serialization.
    • Preserve existing behavior when inputs is present (still emits serialized sample input payload).
  • Regression coverage

    • Added a focused unit test for format_llm_response(..., inputs=None) to ensure the function returns successfully and emits sample_input == "".
  • Changelog

    • Added an unreleased bug-fix entry documenting the UnboundLocalError fix.
input_str = f"{json.dumps(inputs)}" if inputs else ""
sample_input = ""
if inputs and len(inputs) > 0:
    sample_input_json = []
    msg = ChatCompletionUserMessageParam(role="user", content=input_str)
    sample_input_json.append(msg)
    sample_input = json.dumps(sample_input_json)

@github-actions github-actions Bot added the Evaluation Issues related to the client library for Azure AI Evaluation label May 19, 2026
@posaninagendra posaninagendra marked this pull request as ready for review May 19, 2026 23:34
@posaninagendra posaninagendra requested a review from a team as a code owner May 19, 2026 23:34
Copilot AI review requested due to automatic review settings May 19, 2026 23:34
@posaninagendra posaninagendra enabled auto-merge (squash) May 19, 2026 23:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes an UnboundLocalError in prompty response formatting when format_llm_response is invoked without inputs (seen in async evaluator flows), and adds regression coverage plus a changelog entry.

Changes:

  • Initialize sample_input to "" so format_llm_response(..., inputs=None) can’t reference it before assignment.
  • Add a unit test validating the inputs=None path returns successfully and sets sample_input to an empty string.
  • Document the fix in the unreleased changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_legacy/prompty/_utils.py Initializes sample_input defensively to prevent UnboundLocalError when inputs is omitted.
sdk/evaluation/azure-ai-evaluation/tests/unittests/test_prompty_format_llm_response.py Adds regression test covering format_llm_response(..., inputs=None) behavior.
sdk/evaluation/azure-ai-evaluation/CHANGELOG.md Notes the bug fix in the unreleased section.

@github-actions
Copy link
Copy Markdown
Contributor

Hi @copilot. We've noticed that new changes have been pushed to this pull request. Because it is set to automatically merge, we've reset the approvals to allow the opportunity to review the updates.

@posaninagendra posaninagendra merged commit c922d8f into main May 20, 2026
19 checks passed
@posaninagendra posaninagendra deleted the copilot/fix-unbound-local-variable-sample-input branch May 20, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Evaluation Issues related to the client library for Azure AI Evaluation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants