Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PDF artifact not being OCR’d by ADK #2016

@Dill777

Description

@Dill777

Problem

Sending a PDF as a Part with mime_type='application/pdf' but the agent:

  • Always asks for “raw text”.
  • Returns made-up data that doesn’t match the PDF.

Steps

  1. Create session
  2. Save PDF via artifact_service.save_artifact
  3. Send:
    content = Content(parts=[
        Part(text=f"Patient folder: {patient_id}"),
        Part.from_bytes(pdf_bytes, mime_type="application/pdf")
    ])
    async for event in runner.run_async(...):
        ...
  4. Agent never invokes OCR or analyze_attachment.

Questions

  1. Is sending PDF Parts directly supported?
  2. How to trigger OCR (built‑in or custom tool) on a PDF artifact?
  3. Should I pre-convert PDFs to text/images instead?

I'm using 2.5 pro model, that should support PDF. Any examples in ADK repos appreciated.

            pdf_part = Part.from_bytes(
                data=pdf_bytes,
                mime_type="application/pdf"
            )

            session_id = f"{patient_id}_{filename}"
            await session_service.create_session(
                app_name=APP_NAME,
                user_id=USER_ID,
                session_id=session_id
            )

            version = await artifact_service.save_artifact(
                app_name=APP_NAME,
                user_id=USER_ID,
                session_id=session_id,
                filename=filename,
                artifact=pdf_part
            )

            content = Content(parts=[
                Part(text=f"Patient folder: {patient_id}"),
                pdf_part
            ])

            async for event in runner.run_async(
                user_id=USER_ID,
                session_id=session_id,
                new_message=content
            )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bot triaged[Bot] This issue is triaged by ADK botquestion[Component] This issue is asking a question or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions