Entity Extraction JSON
json_capabilitiesgemini-cookbookgemini-apiexamplesgemini
Export
Copyright 2025 Google LLC.
[ ]
Gemini API: Entity Extraction
You will use Gemini to extract all fields that fit one of the predefined classes and label them.
[5]
Configure your API key
To run the following cell, your API key must be stored it in a Colab Secret named GOOGLE_API_KEY. If you don't already have an API key, or you're not sure how to create a Colab Secret, see Authentication for an example.
[6]
Example
[7]
MODEL_ID
[8]
{
"entities": [
{
"name": "John Johnson",
"category": "Person"
},
{
"name": "Oil Inc.",
"category": "Company"
},
{
"name": "Coal Inc.",
"category": "Company"
},
{
"name": "Houston",
"category": "City"
},
{
"name": "Texas",
"category": "State"
}
]
}
Summary
You have used the Gemini API to extract entities of predefined categories with their labels. You extracted every person, company, state, and country. You are not limited to these categories, as this should work with any category of your choice.
Please see the other notebooks in this directory to learn more about how you can use the Gemini API for other JSON related tasks.