Skip to content

NerdlystTech · Markets · Code

langchain-perplexity 1.4.2: The Fix for Vanishing Search Results

Glowing code on a dark screen for the langchain-perplexity 1.4.2 release
Photo by Chris Ried on Unsplash

If you built a LangChain app on Perplexity’s Agent API and your source list kept coming back empty, the problem was in the library, not your code. langchain-perplexity 1.4.2, released on 21 October 2026, fixes a silent bug that threw away every search result the Agent API sent back, while the answer text still looked fine.

Key takeaways

  • On the Agent API path, ChatPerplexity left additional_kwargs["search_results"] empty, and it raised no error.
  • The fix (PR #41349) covers invoke, ainvoke, stream and astream.
  • The bug was reported on 20 October 2026 and merged the next day.
  • Plain Chat Completions calls, such as model="sonar" with no built-in tools, were never affected.
  • The release also bumps certifi, urllib3 and anyio and refreshes model profile data.

What did langchain-perplexity 1.4.2 actually fix?

The headline change is “fix(perplexity): preserve Agent API search results”. Before it, the list of web pages Perplexity looked at to write an answer never made it into the LangChain response object.

That matters because the LangChain Perplexity docs tell you to read sources from response.additional_kwargs["search_results"]. Each entry carries a title, a URL and a date. If you show citations to users, store them for audits or check them in an evaluation pipeline, that field is the whole point of using a search-grounded model.

Think of it like a restaurant that serves your meal but bins the receipt. You got fed, but you can’t prove what you paid for.

Python code on a laptop screen for a langchain-perplexity 1.4.2 upgrade
Photo by Safar Safarov on Unsplash

Why did the search results disappear?

ChatPerplexity can talk to two different Perplexity endpoints. Chat Completions is the classic one. The Agent API is Perplexity’s Responses-style endpoint, which gives models built-in tools such as web_search, fetch_url, finance_search and people_search.

The two endpoints package sources differently. According to issue #41348, filed by developer Ant White on 20 October 2026, LangChain’s response converter only looked for a top-level search_results field. The Agent API puts sources inside nested output items instead. On the streaming side, the converter skipped the response.reasoning.search_results events completely.

The result was the worst kind of bug: nothing crashed. The answer text arrived as normal, so the only way to notice was to check whether the sources list was empty.

Were you affected? A quick comparison

It depends on which endpoint your calls went to. By default, use_responses_api=None picks the endpoint for you: it switches to the Agent API whenever you pass a built-in tool or a Responses-only field such as instructions, input, include or previous_response_id.

Your setupEndpoint usedSources before 1.4.2
ChatPerplexity(model="sonar"), no built-in toolsChat CompletionsPresent
use_responses_api=FalseChat CompletionsPresent
use_responses_api=TrueAgent APIMissing
Default flag plus tools=[{"type": "web_search"}]Agent API (auto-detected)Missing
Default flag plus instructions or previous_response_idAgent API (auto-detected)Missing

The auto-detection rows are the sneaky ones. You could have moved to the Agent API without meaning to, just by adding a web search tool.

How the fix works

The patch now walks the Agent API output, finds items whose type is search_results, and appends their results to additional_kwargs["search_results"], the same place the Chat Completions path already uses. In streaming mode it turns each source into a plain dictionary with model_dump(), as the Chat Completions code does, and it makes sure results aren’t sent a second time when the final response.completed event arrives.

The review was more careful than you might expect for a point release. Maintainer Bicheng (Kenneth) ran the change against the real Perplexity SDK over mocked HTTP and confirmed that sources survived without duplicates. An automated reviewer spotted that invoke and stream returned different data types, so the author revised the patch before maintainer ccurme merged it on 21 October 2026. The new regression tests cover sync and async calls, several batches of sources and duplicate prevention.

Developer reviewing code changes on a monitor
Photo by Mohammad Rahmani on Unsplash

What else is in the release?

The GitHub release notes list several smaller changes since 1.4.1:

  • Responses API cache tokens now map into input_token_details (#39923), which helps if you track cost per call.
  • search_context_size is emitted once per stream in _astream instead of repeating (#39924).
  • Updated ChatPerplexity docstring examples for the Agent API (#39831).
  • Dependency bumps: certifi to 2026.10.19, urllib3 2.7.0 to 2.8.0, anyio 4.11.0 to 4.14.2.
  • Refreshed model profile data and dependency fixes across partner packages.

My take: the certifi bump alone is a fair reason to upgrade, since it ships the latest set of trusted certificate authorities. The search results fix is the real reason.

How to upgrade and check your app

Run pip install -U langchain-perplexity==1.4.2, or the same with uv pip if you use uv (our uv 0.13.3 piece covers a recent fix there). Then add one cheap check: after an Agent API call with web_search, assert that additional_kwargs["search_results"] isn’t empty.

That one-line assertion belongs in your test suite for good. Silent data loss like this is exactly what our AI agent evaluation checklist is meant to catch before users do.

Server racks representing web search APIs behind AI agents
Photo by Tyler on Unsplash

What happens next

The Agent API support in ChatPerplexity still has rough edges you should know about. On that path, temperature, top_p, top_k, stop and metadata are dropped with a warning, and passing tool_choice raises a ValueError. Expect more point releases as the two code paths are brought in line.

If you’re still deciding how to structure the agent around this model, our guide to LangChain vs LangGraph walks through the choice.

FAQ

Does langchain-perplexity 1.4.2 change my code?

No. You read sources from the same additional_kwargs["search_results"] field as before. On the Agent API path it now actually has data in it.

Did the bug affect streaming?

Yes. Sources were lost in stream and astream as well as in invoke and ainvoke. Version 1.4.2 fixes all four and avoids sending results twice at the end of a stream.

I only use the sonar model. Do I need to upgrade?

Plain Chat Completions calls were not affected by the search results bug. Upgrading is still worth it for the dependency updates and the token accounting fix.

Your next step: upgrade, run one Agent API call with web_search, and check that your sources list is no longer empty.

Leave a comment

Leave a Reply