Skip to content

Parse inference response format defensively#97

Merged
sgoedecke merged 1 commit intomainfrom
sgoedecke/defensive-parsing
Aug 24, 2025
Merged

Parse inference response format defensively#97
sgoedecke merged 1 commit intomainfrom
sgoedecke/defensive-parsing

Conversation

@sgoedecke
Copy link
Contributor

#96

It looks like there was a period where the API was responding without the JSON content type. That shouldn't happen, but if it does we don't need to fail inference on our end either. This PR checks the inference response to see if it's a string and parses it into JSON if so.

Copilot AI review requested due to automatic review settings August 22, 2025 22:35
@sgoedecke sgoedecke requested a review from a team as a code owner August 22, 2025 22:35
Copy link
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

This PR implements defensive parsing of OpenAI API responses to handle cases where the API returns a string instead of a properly parsed JSON object. It centralizes response handling logic and removes duplicate error handling code.

  • Adds a new chatCompletion wrapper function that defensively parses string responses from the OpenAI API
  • Refactors both simpleInference and mcpInference functions to use the centralized wrapper
  • Removes duplicate response validation and error handling code

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sgoedecke sgoedecke merged commit a1c1182 into main Aug 24, 2025
23 checks passed
@sgoedecke sgoedecke deleted the sgoedecke/defensive-parsing branch August 24, 2025 22:47
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.

3 participants