Problem while sending multimodal conversation history based prompt via genai sdk

client=genai.Client()
filess=client.files.upload(file="uploaded_stuffs/2025-11-16-19-18-51-101131.png")
u=client.models.generate_content(
        model="gemini-2.5-flash",
        contents=[
            {
                "role":"user",
                "parts":[
                    {"text":"Hey so i wanted to test if i could upload my files properly so this is that"},
                    {"fileData":{
                        "fileUri":filess.name,
                        "mimeType":filetype.guess("uploaded_stuffs/2025-11-16-19-18-51-101131.png").mime,
                        "fileName":os.path.basename("uploaded_stuffs/2025-11-16-19-18-51-101131.png")
                    }}
                ]
            }
        ]
        ) 
print(u.text)

I was running this code to test which format is supported by the genai sdk’s generate_content() method but i keep getting errors. I have looked everywhere i could find to figure out which format is the correct one for the content parameter but couldnt get it to work. I was initially sending only text and sending the conversation history with everything just like how it was shown in the code only that fileData key wasnt there as I didnt upload a file then and everything seemed to work just fine. Can anyone tell me what’s wrong here?
The following is the traceback error i kept getting

Traceback (most recent call last):
  File "E:\MulmA\MulmA.py", line 396, in <module>
    u=client.models.generate_content(
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\MulmA\venv\Lib\site-packages\google\genai\models.py", line 5076, in generate_content
    response = self._generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\MulmA\venv\Lib\site-packages\google\genai\models.py", line 3816, in _generate_content
    parameter_model = types._GenerateContentParameters(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\MulmA\venv\Lib\site-packages\pydantic\main.py", line 253, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 19 validation errors for _GenerateContentParameters
contents.Content
  Input should be a valid dictionary or object to extract fields from [type=model_attributes_type, input_value=[{'role': 'user', 'parts'...9-18-51-101131.png'}}]}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/model_attributes_type
contents.str
  Input should be a valid string [type=string_type, input_value=[{'role': 'user', 'parts'...9-18-51-101131.png'}}]}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type
contents.is-instance[Image]
  Input should be an instance of Image [type=is_instance_of, input_value=[{'role': 'user', 'parts'...9-18-51-101131.png'}}]}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
contents.File
  Input should be a valid dictionary or object to extract fields from [type=model_attributes_type, input_value=[{'role': 'user', 'parts'...9-18-51-101131.png'}}]}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/model_attributes_type
contents.Part
  Input should be a valid dictionary or object to extract fields from [type=model_attributes_type, input_value=[{'role': 'user', 'parts'...9-18-51-101131.png'}}]}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/model_attributes_type
contents.list[union[str,is-instance[Image],File,Part]].0.str
  Input should be a valid string [type=string_type, input_value={'role': 'user', 'parts':...19-18-51-101131.png'}}]}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type
contents.list[union[str,is-instance[Image],File,Part]].0.is-instance[Image]
  Input should be an instance of Image [type=is_instance_of, input_value={'role': 'user', 'parts':...19-18-51-101131.png'}}]}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
contents.list[union[str,is-instance[Image],File,Part]].0.File.role
  Extra inputs are not permitted [type=extra_forbidden, input_value='user', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[str,is-instance[Image],File,Part]].0.File.parts
  Extra inputs are not permitted [type=extra_forbidden, input_value=[{'text': 'Hey so i wante...-19-18-51-101131.png'}}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[str,is-instance[Image],File,Part]].0.Part.role
  Extra inputs are not permitted [type=extra_forbidden, input_value='user', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[str,is-instance[Image],File,Part]].0.Part.parts
  Extra inputs are not permitted [type=extra_forbidden, input_value=[{'text': 'Hey so i wante...-19-18-51-101131.png'}}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.Content.parts.1.fileData.fileName
  Extra inputs are not permitted [type=extra_forbidden, input_value='2025-11-16-19-18-51-101131.png', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.str
  Input should be a valid string [type=string_type, input_value={'role': 'user', 'parts':...19-18-51-101131.png'}}]}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/string_type
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.is-instance[Image]
  Input should be an instance of Image [type=is_instance_of, input_value={'role': 'user', 'parts':...19-18-51-101131.png'}}]}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.File.role
  Extra inputs are not permitted [type=extra_forbidden, input_value='user', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.File.parts
  Extra inputs are not permitted [type=extra_forbidden, input_value=[{'text': 'Hey so i wante...-19-18-51-101131.png'}}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.Part.role
  Extra inputs are not permitted [type=extra_forbidden, input_value='user', input_type=str]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.Part.parts
  Extra inputs are not permitted [type=extra_forbidden, input_value=[{'text': 'Hey so i wante...-19-18-51-101131.png'}}], input_type=list]
    For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
contents.list[union[Content,str,is-instance[Image],File,Part,list[union[str,is-instance[Image],File,Part]]]].0.list[union[str,is-instance[Image],File,Part]]
  Input should be a valid list [type=list_type, input_value={'role': 'user', 'parts':...19-18-51-101131.png'}}]}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/list_typetype or paste code here

Hi @Nafiz_Shahriar,

The ValidationError arises because the generate_content method expects file parts to be represented by a genai.Part object, specifically one created using genai.Part.from_file(), rather than a manually constructed dictionary

Here is a modified code snippet

# MODIFIED CODE SNIPPET
contents_with_image = [
    {
        "role": "user",
        "parts": [
            {"text": "Hey so I wanted to test if I could upload my files properly, so this is that"},
            genai.Part.from_file(uploaded_file) # Use genai.Part.from_file() with the uploaded file object
        ]
    }
]

u = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=contents_with_image
)
print(u.text)