Skip to content

fix: add missing _parse_response to AzureOpenAIStructuredLLM#4434

Merged
kartik-mem0 merged 1 commit intomem0ai:mainfrom
mvanhorn:osc/4164-azure-structured-llm-parse-response
Mar 20, 2026
Merged

fix: add missing _parse_response to AzureOpenAIStructuredLLM#4434
kartik-mem0 merged 1 commit intomem0ai:mainfrom
mvanhorn:osc/4164-azure-structured-llm-parse-response

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Description

AzureOpenAIStructuredLLM calls self._parse_response(response, tools) at line 91 of generate_response(), but the method is not defined in the class or its parent LLMBase. This causes an AttributeError at runtime when using Azure OpenAI as the structured LLM provider.

The sibling class OpenAIStructuredLLM in openai_structured.py has a working _parse_response, and other LLM classes (vllm, lmstudio, gemini, aws_bedrock) all define their own. AzureOpenAIStructuredLLM was the only one missing it.

Also removed a duplicate if tools: block (lines 82-84 and 86-88 were identical).

Fixes #4164

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test

Added tests/llms/test_azure_openai_structured.py with 3 tests:

  • test_generate_response_without_tools - verifies plain text response path
  • test_generate_response_with_tools - verifies tool call parsing returns dict with content and tool_calls
  • test_generate_response_with_tools_no_tool_calls - verifies tools provided but model returns no calls

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Maintainer Checklist

This contribution was developed with AI assistance (Claude Code).

AzureOpenAIStructuredLLM calls self._parse_response() but the method
was not defined in the class or its parent LLMBase, causing an
AttributeError at runtime. Added the method matching the pattern used
by the non-structured AzureOpenAILLM sibling class. Also removed a
duplicate `if tools:` block.

Fixes mem0ai#4164

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 19, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@xkonjin xkonjin left a comment

Choose a reason for hiding this comment

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

Code Review: Add missing _parse_response to AzureOpenAIStructuredLLM

Good catch on a real bug. The class was missing the _parse_response method that other LLM providers implement, meaning tool calls from Azure OpenAI would have been returned raw rather than in the expected format.

What looks good

  • The _parse_response implementation matches the pattern from other LLM providers (OpenAILLM etc.).
  • Removes the duplicate tools/tool_choice parameter assignment (lines 86-88 were setting the same params twice).
  • Tests cover all three scenarios: no tools, tools with tool calls, tools without tool calls.
  • Uses extract_json for parsing tool call arguments, which handles potential JSON formatting issues.

Issues

1. No error handling in _parse_response (medium risk)
If response.choices is empty, or choices[0].message is None, this will raise an IndexError/AttributeError. Other providers may handle this differently, but it is worth adding a guard:

if not response.choices:
    return ''

Check how the base OpenAI provider handles this and match the pattern.

2. extract_json wrapped in json.loads

json.loads(extract_json(tool_call.function.arguments))

If extract_json already returns a parsed dict (check its return type), json.loads would fail on a dict input. If it returns a string, this is fine. Verify the contract of extract_json. If it returns a string, consider adding a try/except for malformed JSON in tool arguments.

Minor

  • The import of json at line 1 is correctly added since it is used in _parse_response.

LGTM with the empty response guard noted above.

@kartik-mem0 kartik-mem0 merged commit 4437c3e into mem0ai:main Mar 20, 2026
6 of 7 checks passed
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks for the merge!

@kartik-mem0
Copy link
Copy Markdown
Contributor

@mvanhorn thank you for your contribution.

jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
…4434)

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

AzureOpenAIStructuredLLM missing _parse_response method

4 participants