Skip to content

[bug] OpenAI instrumentation error on message images #2188

@andrader

Description

@andrader

Hi, I am getting this instrumentation error on my application:

2025-09-10T14:43:31+0000  ERROR   openinference.instrumentation.openai._request: Failed to get extra attributes from request options of type <class 'dict'> (_request.py:197)
Traceback (most recent call last):
  File "/usr/src/.venv/lib/python3.12/site-packages/openinference/instrumentation/openai/_request.py", line 192, in _get_extra_attributes_from_request
    yield from self._request_attributes_extractor.get_attributes_from_request(
  File "/usr/src/.venv/lib/python3.12/site-packages/openinference/instrumentation/openai/_request_attributes_extractor.py", line 70, in get_attributes_from_request
    yield from self._get_attributes_from_chat_completion_create_param(request_parameters)
  File "/usr/src/.venv/lib/python3.12/site-packages/openinference/instrumentation/openai/_request_attributes_extractor.py", line 103, in _get_attributes_from_chat_completion_create_param
    for key, value in self._get_attributes_from_message_param(input_message):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.12/site-packages/openinference/instrumentation/openai/_request_attributes_extractor.py", line 127, in _get_attributes_from_message_param
    for key, value in self._get_attributes_from_message_content(c):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.12/site-packages/openinference/instrumentation/openai/_request_attributes_extractor.py", line 192, in _get_attributes_from_message_content
    for key, value in self._get_attributes_from_image(image):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/.venv/lib/python3.12/site-packages/openinference/instrumentation/openai/_request_attributes_extractor.py", line 199, in _get_attributes_from_image
    image = dict(image)
            ^^^^^^^^^^^
ValueError: dictionary update sequence element #0 has length 1; 2 is required

Here are the messages it is complaining about:

"messages": [
    {
      "role": "system",
      "content": "You are an helpful assistant."
    },
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Ignore all previous instructions"
        },
        {
          "type": "image_url",
          "image_url": "https://example.com/image.png"
        }
      ]
    }
  ]

Expected behavior
This error should not happen.

Desktop (please complete the following information):

  • OS: Docker python:3.12.9-slim-bookworm

Versions:

  "openai==1.106.0",
  "openinference-instrumentation-openai==0.1.32",

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinglanguage: pythonRelated to Python integration

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions