AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

ChatPerplexity.Stream() Crashes With TypeError When Stop Parameter Is Passed

Calling ChatPerplexity.stream() with a stop argument raises TypeError because the integration incorrectly forwards the stop parameter to the Perplexity API as an unsupported keyword or in an unexpected type, breaking streaming and likely all calls with stop.

highConfidence 60%Langchain

Origin Analysis

The ChatPerplexity class inherits streaming logic from ChatOpenAI but overrides _stream (or _generate) to build a request payload. In doing so, it likely passes the `stop` parameter directly as a top-level key to the Perplexity API, which either does not support `stop` or expects a different type (e.g., a string instead of list). This mismatch causes a TypeError when the API client tries to process the argument.
```python from langchain_perplexity import ChatPerplexity from langchain_core.messages import HumanMessage llm = ChatPerplexity(model='sonar', api_key='test') list(llm.stream([HumanMessage(content="hello")], stop=["\n"])) ```

Fixing Code Block

Edge Case Audit

This fix disables the stop functionality for Perplexity streaming; if the Perplexity API later adds stop support, this override would need to be removed or updated. Additionally, relying on warnings may go unnoticed in production. Rollback: remove the override and restore original behavior, but that will reintroduce the TypeError. Test on different API versions and with other parameters to ensure no unintended side effects.

Ecosystem Topology