Is there any way to just ignore this and do a retr...
# marvin-ai
d
Is there any way to just ignore this and do a retry or something else?
Copy code
4:16:39.983 | ERROR   | Task run 'Run LLM' - Task run failed with exception: APIError('The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.') - Retries are exhausted
Traceback (most recent call last):
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/prefect/task_engine.py", line 739, in run_context
    yield self
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/prefect/task_engine.py", line 1283, in run_task_sync
    engine.call_task_fn(txn)
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/prefect/task_engine.py", line 762, in call_task_fn
    result = call_with_parameters(self.task.fn, parameters)
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/prefect/utilities/callables.py", line 206, in call_with_parameters
    return fn(*args, **kwargs)
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/controlflow/controllers/controller.py", line 291, in run_once
    for _ in response_gen:
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/controlflow/llm/completions.py", line 307, in _handle_events
    for event in generator:
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/controlflow/llm/completions.py", line 161, in _completion_generator
    for i, delta in enumerate(model.stream(input=input_messages, **kwargs)):
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/langchain_core/runnables/base.py", line 5265, in stream
    yield from self.bound.stream(
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 425, in stream
    raise e
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 405, in stream
    for chunk in self._stream(messages, stop=stop, **kwargs):
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/langchain_openai/chat_models/base.py", line 524, in _stream
    for chunk in response:
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/openai/_streaming.py", line 46, in __iter__
    for item in self._iterator:
  File "/home/dave/.cache/pypoetry/virtualenvs/rustmonster-GKhQY2Y4-py3.10/lib/python3.10/site-packages/openai/_streaming.py", line 72, in __stream__
    raise APIError(
openai.APIError: The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.
j
This is an error we see frequently with gpt-4o-mini and is on the OpenAI side; we've been unable to solve it on the CF side. It has something to do with the model trying to use a tool in an invalid way
d
Yes I've gotten this with other toolchains as well
This is one reason I ended up switching to turbo for most of my work
The proper thing to do is find a way to handle the error though
The good thing is you have workflow management already so you can pretty much just step back into the workflow and retry
j
the error is deterministic for a certain tool JSON payload, it can't be retried
d
I mean for the record I don't use mini for anything
j
Unfortunately the tool in question are the ones CF relies on, I wish OpenAI would at least publish what confuses the model
d
I assume you mean the success and fail tools?
I think what's probably happening is the system message is just getting really large and maybe when the context is too big it stops following instructions
j
No, I had a way to replicate this on the first call. It's the success tools but in conjunction with a very specific setup of other messages
and I frankly don't understand what that is
d
Is there some sort of prefix we can add to force it out of this error mode when it occurs ?