diff --git a/libs/community/langchain_community/utilities/google_lens.py b/libs/community/langchain_community/utilities/google_lens.py index 028c4092a5b..98b796fddad 100644 --- a/libs/community/langchain_community/utilities/google_lens.py +++ b/libs/community/langchain_community/utilities/google_lens.py @@ -65,7 +65,10 @@ class GoogleLensAPIWrapper(BaseModel): return "Google Lens search failed" xs = "" - if len(responseValue["knowledge_graph"]) > 0: + if ( + "knowledge_graph" in responseValue + and len(responseValue["knowledge_graph"]) > 0 + ): subject = responseValue["knowledge_graph"][0] xs += f"Subject:{subject['title']}({subject['subtitle']})\n" xs += f"Link to subject:{subject['link']}\n\n" @@ -74,10 +77,11 @@ class GoogleLensAPIWrapper(BaseModel): xs += f"Title: {image['title']}\n" xs += f"Source({image['source']}): {image['link']}\n" xs += f"Image: {image['thumbnail']}\n\n" - xs += ( - "Reverse Image Search" - + f"Link: {responseValue['reverse_image_search']['link']}\n" - ) + if "reverse_image_search" in responseValue: + xs += ( + "Reverse Image Search" + + f"Link: {responseValue['reverse_image_search']['link']}\n" + ) print(xs) # noqa: T201 docs = [xs]