Error: custom stop words are not implemented for completions

Getting this error with Perplexity models: litellm.exceptions.BadRequestError: litellm.BadRequestError: PerplexityException - Error code: 400 - {'error': {'message': 'custom stop words are not implemented for completions.', 'type': 'unsupported_parameter', 'code': 400}} .

Code to replicate:

import os

from dotenv import load_dotenv
from crewai import Agent, Task, Crew, LLM
from pydantic import BaseModel
from typing import Optional


load_dotenv()

class GreetingOutput(BaseModel):
    message: str
    recipient: Optional[str] = "World"
    sentiment: Optional[str] = "positive"

    def __str__(self):
        return f"{self.message} {self.recipient}! (Sentiment: {self.sentiment})"


llm = LLM(
    api_key=os.environ.get('PERPLEXITY_API_KEY'),
    temperature=0.01,
    model="perplexity/sonar",
)

hello_agent = Agent(
    role='Greeter',
    goal='Deliver friendly greetings',
    backstory='A cheerful agent whose purpose is to greet people warmly',
    llm=llm,
)

greeting_task = Task(
    description="""Generate a friendly hello world message. 
    Your response should be formatted as a JSON object with the following fields:
    - message: The greeting message
    - recipient: Who the message is for (default: "World")
    - sentiment: The emotional tone of the message (default: "positive")
    """,
    expected_output="Instance of GreetingOutput model",
    agent=hello_agent,
    output_pydantic=GreetingOutput,
)

crew = Crew(
    agents=[hello_agent],
    tasks=[greeting_task]
)

result = crew.kickoff()
print(result.pydantic.sentiment)

There was similar error with o1 mini model mentioned, so I don’t think it is Perplexity specific. Looks like CrewAI pushes some stop word, even if you ask it not to.

I am getting this error as well and tried the hack proposed in this GitHub issue but then it just returned a 500 rather than a 400:

litellm.llms.openai.common_utils.OpenAIError: Error code: 500 - {'error': {'message': 'The inference server returned an error.', 'type': 'unknown', 'code': 500}}

I’m using OpenAI clients for other agents which are performing as expected, so it’s not a matter of neglecting an OpenAI API key or the like, and the same code worked in earlier versions of Python/CrewAI. I’m currently using Python 3.11.11 due to issues with ChromaDB and 3.12.