Skip to content

Conversation

@Akash-Kumar-Sen
Copy link

@Akash-Kumar-Sen Akash-Kumar-Sen commented Nov 11, 2025

Description

  • Gemini structured_predict was failing when called inside a synchronous method that is inside an asyncio event loop.
  • Use from llama_index.core.async_utils import asyncio_run instead of asyncio.run() to make sure the synchronous methods also work inside a asyncio event loop.

Regression caused in PR:

Type of Change

Please delete options that are not relevant.

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

How Has This Been Tested?

  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • 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
  • I ran uv run make format; uv run make lint to appease the lint gods

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Nov 11, 2025
}
params = {**kwargs, "generation_config": generation_config}
next_msg, chat_kwargs = asyncio.run(
next_msg, chat_kwargs = asyncio_run(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not actually sure if this will solve the issue or not.

I think Ideally, we remove the need for asyncio.run completely from the sync code-path

Copy link
Author

Choose a reason for hiding this comment

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

I am writing in detail how we encountered this issue:

Steps to reproduce:

  • Call the GoogleGenAI.structured_predict from an asynchronous method

Now there could be two possible solutions:

  1. Completely unwrap the asyncio.run and create synchronous alternatives for whatever is inside.
  2. Remove all synchronous methods and just replace synchronous method = asyncio_run(asynchronous method)

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

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants