Skip to content

# DOCX File not processing in adk #4726

@VenkateshM0631

Description

@VenkateshM0631

Description:
When uploading DOCX files to an ADK agent that uses load_artifacts(), the agent exhibits different failures depending on environment:

  • Local (adk web): Crashes with 400 INVALID_ARGUMENT - MIME type application/vnd.openxmlformats-officedocument.wordprocessingml.document is not supported by Gemini
  • After deployment (Vertex AI Agent Engine): Agent "hallucinates" - ignores instructions and fails to extract/process text correctly, even with explicit prompts

PDF and TXT files work correctly in both environments.

Steps to Reproduce:

  1. Install google-adk
  2. Create an agent with load_artifacts tool and simple instruction: "Extract text from uploaded document and return the text"
  3. Test locally with adk web:
    • Upload PDF file → Works correctly ✅
    • Upload TXT file → Works correctly ✅
    • Upload DOCX file → Crashes with MIME type error ❌
  4. Deploy to Vertex AI Agent Engine: adk deploy agent_engine --project=PROJECT_ID --region=us-central1
  5. Test deployed agent in Gemini Enterprise:
    • Upload PDF file → Works correctly ✅
    • Upload TXT file → Works correctly ✅
    • Upload DOCX file → Agent hallucinates, doesn't follow instructions ❌

Expected Behavior:

  • load_artifacts() should extract plain text from DOCX files (as it does for PDF)
  • Agent should receive clean text string from DOCX content
  • Agent should follow instructions and process DOCX text the same way as TXT/PDF

Observed Behavior:

Local Environment (adk web):

google.genai.errors.ClientError: 400 INVALID_ARGUMENT. 
{'error': {'code': 400, 'message': 'Unable to submit request because it has a mimeType parameter with value application/vnd.openxmlformats-officedocument.wordprocessingml.document, which is not supported. Update the mimeType and try again. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini', 'status': 'INVALID_ARGUMENT'}}

Deployed Environment (Vertex AI Agent Engine):

  • No error thrown
  • Agent processes DOCX but ignores instructions
  • Agent behavior becomes unpredictable/"hallucinates"
  • Same prompt works perfectly with PDF/TXT files

Environment Details:

  • ADK Library Version: google-adk (tried with multiple versions)
  • Desktop OS: Windows
  • Python Version: Python 3.12

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-pro (also tested with gemini-flash)

🟡 Optional Information

Logs:

Local Environment Error (adk web):

2026-03-05 23:50:00,628 - INFO - google_llm.py:185 - Sending out request, model: gemini-2.5-flash, backend: GoogleLLMVariant.VERTEX_AI, stream: False
2026-03-05 23:50:05,271 - ERROR - adk_web_server.py:1629 - Error in event_generator: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Unable to submit request because it has a mimeType parameter with value application/vnd.openxmlformats-officedocument.wordprocessingml.document, which is not supported. Update the mimeType and try again. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini', 'status': 'INVALID_ARGUMENT'}}
Traceback (most recent call last):
  File "C:\Users\Venkatesh.M\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\adk\cli\adk_web_server.py", line 1602, in event_generator
    async for event in agen:
  File "C:\Users\Venkatesh.M\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\adk\runners.py", line 561, in run_async
    async for event in agen:
  [... full traceback ...]
  File "C:\Users\Venkatesh.M\AppData\Local\Programs\Python\Python312\Lib\site-packages\google\genai\errors.py", line 238, in raise_error_async
    raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Unable to submit request because it has a mimeType parameter with value application/vnd.openxmlformats-officedocument.wordprocessingml.document, which is not supported. Update the mimeType and try again. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini', 'status': 'INVALID_ARGUMENT'}}

Additional Context:

Root Cause Analysis:
DOCX files are ZIP archives containing XML (word/document.xml). The issue appears to be:

  1. Local: load_artifacts() passes raw DOCX file to Gemini instead of extracting text first
  2. Deployed: load_artifacts() may extract text but includes XML artifacts/metadata that confuses the model

Comparison:

  • TXT: ✅ Plain text, works everywhere
  • PDF: ✅ Text extraction works, model receives clean text
  • DOCX: ❌ Different failures local vs deployed

Minimal Reproduction Code:

from google.adk.agents import Agent
from google.adk.apps import App
from google.adk.tools import load_artifacts
from google.adk.tools.function_tool import FunctionTool

def process_text(document_text: str) -> str:
    """Simple function that returns the text."""
    return f"Extracted text length: {len(document_text)} characters\n\n{document_text}"

process_text_tool = FunctionTool(process_text)

root_agent = Agent(
    name="docx_test",
    model="gemini-2.5-flash",
    instruction="""
When user uploads a document:
1. Call load_artifacts() to extract text
2. Pass the extracted text to process_text tool
3. Return the result
""",
    tools=[load_artifacts, process_text_tool],
)

app = App(name="docx_test", root_agent=root_agent)

# Test:
# - Upload TXT file → Works ✅
# - Upload PDF file → Works ✅  
# - Upload DOCX file → Fails ❌ (MIME type error locally, hallucination when deployed)

How often has this issue occurred?:

  • Always (100%) - Every DOCX file fails in both environments

Impact:
HIGH - DOCX is the most common document format in enterprise environments. This blocks real-world agent deployments.


Metadata

Metadata

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions