Skip to content

Return detailed error output from Gemini API calls. #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 19, 2025

Conversation

mkbehr
Copy link
Collaborator

@mkbehr mkbehr commented May 9, 2025

Restructure the ModelResponse interface to return error information.

  • A new status field contains an enum to indicate whether the response was OK.
  • text is populated only if the model returned a text response. (It will be empty for most error cases, but some errors will leave some text populated, like running out of output tokens.)
  • A new errorMessage field contains the error message.
  • A new parsedResponse field isn't populated yet, but it'll let us move structured output parsing closer to the model call, and return a parsing error if the model returns badly-formatted data.

Errors are reported through the prompt testing endpoint, but otherwise not used yet.

Only the Gemini API is fully supported so far. The OpenAI/compatible API will report UNKNOWN_ERROR for some errors, and the Ollama API will always report OK.

  • Tests pass

@mkbehr mkbehr requested review from vivtsai and cjqian May 9, 2025 22:07
Copy link
Member

@cjqian cjqian left a comment

Choose a reason for hiding this comment

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

LGTM. This structure looks good to me, feel free to proceed! Will leave to @vivtsai to merge.

@@ -310,17 +311,22 @@ export async function getAgentChatAPIResponse(
promptConfig.structuredOutputConfig,
);

if (response.status !== ModelResponseStatus.OK) {
// TODO: Surface the error to the experimenter.
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Some ways I could see this being surfaced:

  • An error icon on both the participant (in the cohort view) and participant chat panel, with the latest error text on hover.
  • Also, something in the alerts panel (perhaps a notification icon in the panel)

@vivtsai

Copy link
Collaborator

Choose a reason for hiding this comment

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

For starters, we'll include the error in a log message (and then yes, we can decide if we want an "error" log message to trigger some sort of visual or other behavior on the frontend).

@@ -49,10 +49,9 @@ function makeStructuredOutputSchema(
};
const type = typeMap[schema.type];
if (!type) {
console.error(
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to throw here or should we just return an empty response with a structured output error?

Copy link
Member

Choose a reason for hiding this comment

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

Here and elsewhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll catch the error in getGeminiApiResponse() and return an error response from there. Directly returning the error from here would be awkward since this is just returning the schema, so throwing it seemed cleaner to me.

if (!response.candidates) {
return {
status: ModelResponseStatus.UNKNOWN_ERROR,
errorMessage: `Response unexpectedly had no candidates: ${response}`,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Make this error more clear (experimenters might not know what candidates are)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about this? Experimenters probably won't be able to deal with this error anyway since it means the provider isn't returning the expected format, but hopefully this will make it clearer that this is probably a provider/platform problem.

@vivtsai vivtsai merged commit 0a24c16 into PAIR-code:main May 19, 2025
1 check passed
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