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

ChatPerplexity.Stream() Crashes With TypeError When Stop Sequences Are Passed

Calling stream() or astream() on ChatPerplexity with a stop argument raises TypeError because the streaming implementation incorrectly sends stop_sequences (an Anthropic parameter) to Perplexity's Chat Completions API, which only accepts stop. The bug breaks streaming for any user passing stop sequences.

highConfidence 95%LangchainAffected V1.4.1

Origin Analysis

The _stream and _astream methods of ChatPerplexity include a redundant stop_sequences=stop parameter in the client.chat.completions.create() call. This parameter is not supported by the Perplexity API (which expects stop, already present) and originates from Anthropic SDK naming, causing a TypeError before any network request.
1. Install langchain-perplexity 1.4.1 and set up API key.\n2. Create a ChatPerplexity instance with model='sonar'.\n3. Run list(llm.stream([HumanMessage(content='Say hello')], stop=['\\n'])).\n4. Observe TypeError: CompletionsResource.create() got an unexpected keyword argument 'stop_sequences'.

Fixing Code Block

Edge Case Audit

The fix is safe for the Perplexity API because stop_sequences was never a valid parameter there; it was an accidental Anthropic-ism. However, if a future version of the Perplexity client or API adds support for stop_sequences (unlikely), this removal would need to be revisited. Rollback suggestion: if this change unexpectedly breaks stopping behavior, restore the line and investigate whether the Perplexity API has changed. Ensure that the stop parameter remains correctly passed and is not accidentally removed during the patch. Test both invoke() and stream() to confirm consistent behavior.

Ecosystem Topology