Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Langfuse craps out when there is an error upstream #2001

Open
ajram23 opened this issue May 7, 2024 · 8 comments
Open

bug: Langfuse craps out when there is an error upstream #2001

ajram23 opened this issue May 7, 2024 · 8 comments
Assignees
Labels

Comments

@ajram23
Copy link

ajram23 commented May 7, 2024

Describe the bug

If there is an upstream error with the service like OpenAI or grok, Langfuse says invalid JSON error

Langfuse craps out when there is an error with groq.RateLimitError: Error code: 429 - {'error': {'message': 'Rate limit reached for model llama3-70b-8192 in organization org_BLAH on tokens per minute (TPM): Limit 7000, Used 1607, Requested ~47333. Please try again in 5m59.484999999s. Visit https://console.groq.com/docs/rate-limits for more information.', 'type': 'tokens', 'code': 'rate_limit_exceeded'}}

Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)
Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)
Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)

Another example groq.BadRequestError: Error code: 400 - {'error': {'message': 'messages.1.content: user message cannot be an null or empty', 'type': 'invalid_request_error'}}

Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)
Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)
Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)

To reproduce

See above

SDK and container versions

No response

Additional information

No response

Are you interested to contribute a fix for this bug?

No

Copy link
Member

do you use groq via the openai integration and host [https://api.groq.com/openai/v1](https://api.groq.com/openai/v1)?

@ajram23
Copy link
Author

ajram23 commented May 7, 2024

Not sure but I have seen this happen with OpenAI as well.

@tommyhe6
Copy link

tommyhe6 commented May 7, 2024

Can confirm that I receive the same error

Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)

when OpenAI errors out too, due to rate limiting.

@marcklingen
Copy link
Member

thanks @tommyhe6 @ajram23! we'll have a look

@maxdeichmann
Copy link
Member

@tommyhe6 @ajram23 does this happen in the langchain integration?

@ajram23
Copy link
Author

ajram23 commented May 8, 2024

@maxdeichmann yes.

@tommyhe6
Copy link

@maxdeichmann I'm not using the langchain integration. We have our own function that calls an LLM API that's wrapped in @observe(as_type="generation"). And our outer functions are wrapped in @observe(). Luckily it doesn't seem to affect performance, but the log is pretty annoying since it makes debugging harder and clutters our Sentry.

@adithya-dinesh
Copy link

adithya-dinesh commented May 13, 2024

@marcklingen
Similar error we are getting on using langfuse with python
Sharing trace

`Giving up execute_task_with_backoff(...) after 3 tries (langfuse.request.APIError: Invalid JSON (400): None)
error uploading: Invalid JSON (400): None
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/langfuse/request.py", line 104, in _process_response
payload = res.json()
^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_models.py", line 756, in json
return jsonlib.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/json/init.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/langfuse/task_manager.py", line 139, in upload
self._upload_batch(batch)
File "/usr/local/lib/python3.11/site-packages/langfuse/task_manager.py", line 166, in _upload_batch
execute_task_with_backoff(batch)
File "/usr/local/lib/python3.11/site-packages/backoff/_sync.py", line 105, in retry
ret = target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/langfuse/task_manager.py", line 164, in execute_task_with_backoff
return self._client.batch_post(batch=batch, metadata=metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/langfuse/request.py", line 57, in batch_post
return self._process_response(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/langfuse/request.py", line 108, in _process_response
raise APIError(res.status_code, res.text)
langfuse.request.APIError: Invalid JSON (400): None`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants