Skip to content

[Bug] Amadeus toolkit fails with Pydantic v2: Client forward reference not resolved #537

@fedei10

Description

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain Community rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain Community.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Example Code

from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit
from langchain_groq import ChatGroq
from amadeus import Client
import os
from app.config import Settings
from amadeus import Client, ResponseError
def loadAmadeusToolkit(llm: ChatGroq):
"""Load the Amadeus toolkit for travel-related queries."""
try:
os.environ["AMADEUS_CLIENT_ID"] = Settings.AMADEUS_CLIENT_ID
os.environ["AMADEUS_CLIENT_SECRET"] = Settings.AMADEUS_CLIENT_SECRET
amadeus_client = Client(
client_id=Settings.AMADEUS_CLIENT_ID,
client_secret=Settings.AMADEUS_CLIENT_SECRET
)
# Force model rebuild before instantiation to resolve Pydantic v2 forward references
# This must be called before creating any instance of AmadeusToolkit
AmadeusToolkit.model_rebuild()

    # Now create the toolkit instance
    amadeus_toolkit = AmadeusToolkit(llm=llm)
    tools = amadeus_toolkit.get_tools()
    print("✅ Amadeus toolkit loaded successfully")
    return tools
except Exception as e:
    print(f"❌ Error loading Amadeus toolkit: {e}")
    return []

Error Message and Stack Trace (if applicable)

❌ Error loading Amadeus toolkit: AmadeusClosestAirport is not fully defined; you should define Client, then call AmadeusClosestAirport.model_rebuild().

Description

Bug Description

The AmadeusToolkit and its associated tools (AmadeusClosestAirport, AmadeusFlightSearch) fail to initialize in Pydantic v2 environments due to unresolved forward references for the Client type from the amadeus library.

Error Message

Root Cause

In base.py, Client is imported only under TYPE_CHECKING:

if TYPE_CHECKING:
    from amadeus import Client

class AmadeusBaseTool(BaseTool):
    client: Client = Field(default_factory=authenticate)  # Unresolved at runtime

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions