In this categoryGemini ยท 24
- How to Install the Gemini CLI and Run Your First PromptStart
- How to Get a Gemini API Key from Google AI Studio
- How to Call the Gemini API from Python
- How to Give Gemini CLI Project Context with a GEMINI.md File
- How to Choose the Right Gemini Model for Coding Tasks
- How to Fix a Bug in Your Codebase with the Gemini CLI
- How to Set Up Gemini Code Assist in VS Code
- How to Stream Gemini Responses in Node.js
- How to Feed a Long Document into Gemini's Long Context
- How to Run the Gemini CLI Non-Interactively in Scripts
- How to Analyze a Video File with the Gemini API
- How to Connect an MCP Server to the Gemini CLI
- How to Fix Common Gemini CLI Authentication Errors
- How to Cache Long Context in the Gemini API to Cut Costs
- How to Summarize a YouTube Video with Gemini
- How to Analyze PDFs and Docs in the Gemini Chat App
- How to Extract Data from Images and Screenshots with Gemini
- How to Generate a Short Video with Veo in Gemini
- How to Ground Gemini Answers in Your Own Documents
- How to Use Gemini Inside Google Docs to Draft Faster
How to Extract Data from Images and Screenshots with Gemini
Hand Gemini a photo of a receipt, whiteboard, or table and get clean structured data back as JSON or a spreadsheet.
Gemini can look at an image and read it, not just transcribe the text but understand the structure of a receipt, a handwritten note, or a screenshot of a table. This guide turns a photo into structured data you can drop into a database or sheet, both in the chat app and via the API.
What you need
- A photo or screenshot containing the data (receipt, table, form)
- A Gemini account, or an API key for the programmatic route
- A target format in mind: JSON, CSV, or a table
Step 1: Attach the image and ask for structure
In the chat app, attach the image with the plus icon, then ask for the data in a specific shape. The key is naming the fields you want, so Gemini does not guess at the schema.
Step 2: Enforce a strict JSON schema (API)
For automation you want JSON every time, not prose. The API supports a response schema that forces the model to return data in your exact structure, which removes the parsing headaches.
import os
from google import genai
from google.genai import types
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
img = client.files.upload(file="receipt.jpg")
schema = {
"type": "object",
"properties": {
"merchant": {"type": "string"},
"date": {"type": "string"},
"total": {"type": "number"},
},
"required": ["merchant", "date", "total"],
}
resp = client.models.generate_content(
model="gemini-2.5-flash",
contents=[img, "Extract the receipt details."],
config=types.GenerateContentConfig(
response_mime_type="application/json",
response_schema=schema,
),
)
print(resp.text)Step 3: Handle multi-row tables
For a screenshot of a table, ask for an array of row objects and name every column. Tell Gemini to leave a field empty rather than invent a value when a cell is blurry or cut off.
Read this table screenshot. Return an array of objects with keys:
name, role, email. If a cell is unreadable, use an empty string,
never guess.Result
You get structured, parseable data from a plain photo. With response_schema in the API the output is reliable enough to feed straight into a spreadsheet, an invoice tool, or a database insert without manual cleanup.
Watch related tutorials
16:12
3:58:44
35:00
12:00
09:00
28:00New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.