{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Copyright 2025 Google LLC\n", "#\n", "# Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# https://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Format LLM output using an output schema\n", "\n", "
\n",
" \n",
" Run in Colab\n",
" \n",
" | \n",
" \n",
" \n",
" \n",
" View on GitHub\n",
" \n",
" | \n",
" \n",
" \n",
" | \n",
"
| \n", " | city | \n", "
|---|---|
| 0 | \n", "Seattle | \n", "
| 1 | \n", "New York | \n", "
| 2 | \n", "Shanghai | \n", "
3 rows × 1 columns
\n", "| \n", " | city | \n", "ml_generate_text_llm_result | \n", "
|---|---|---|
| 0 | \n", "Seattle | \n", "Yes, Seattle is a city in the United States. I... | \n", "
| 1 | \n", "New York | \n", "Yes, New York City is a city in the United Sta... | \n", "
| 2 | \n", "Shanghai | \n", "No, Shanghai is not a US city. It is a major c... | \n", "
3 rows × 2 columns
\n", "| \n", " | city | \n", "is_us_city | \n", "
|---|---|---|
| 0 | \n", "Seattle | \n", "True | \n", "
| 1 | \n", "New York | \n", "True | \n", "
| 2 | \n", "Shanghai | \n", "False | \n", "
3 rows × 2 columns
\n", "| \n", " | city | \n", "population_in_millions | \n", "
|---|---|---|
| 0 | \n", "Seattle | \n", "0.75 | \n", "
| 1 | \n", "New York | \n", "19.68 | \n", "
| 2 | \n", "Shanghai | \n", "26.32 | \n", "
3 rows × 2 columns
\n", "| \n", " | city | \n", "rainy_days | \n", "
|---|---|---|
| 0 | \n", "Seattle | \n", "152 | \n", "
| 1 | \n", "New York | \n", "123 | \n", "
| 2 | \n", "Shanghai | \n", "123 | \n", "
3 rows × 2 columns
\n", "| \n", " | city | \n", "is_US_city | \n", "population_in_millions | \n", "rainy_days_per_year | \n", "
|---|---|---|---|---|
| 0 | \n", "Seattle | \n", "True | \n", "0.75 | \n", "152 | \n", "
| 1 | \n", "New York | \n", "True | \n", "8.8 | \n", "121 | \n", "
| 2 | \n", "Shanghai | \n", "False | \n", "26.32 | \n", "115 | \n", "
3 rows × 4 columns
\n", "| \n", " | city | \n", "is_US_city | \n", "population_in_millions | \n", "rainy_days_per_year | \n", "places_to_visit | \n", "gps_coordinates | \n", "
|---|---|---|---|---|---|---|
| 0 | \n", "Seattle | \n", "True | \n", "0.74 | \n", "150 | \n", "['Space Needle' 'Pike Place Market' 'Museum of... | \n", "{'latitude': 47.6062, 'longitude': -122.3321} | \n", "
| 1 | \n", "New York | \n", "True | \n", "8.4 | \n", "121 | \n", "['Times Square' 'Central Park' 'Statue of Libe... | \n", "{'latitude': 40.7128, 'longitude': -74.006} | \n", "
| 2 | \n", "Shanghai | \n", "False | \n", "26.32 | \n", "115 | \n", "['The Bund' 'Yu Garden' 'Shanghai Museum' 'Ori... | \n", "{'latitude': 31.2304, 'longitude': 121.4737} | \n", "
3 rows × 6 columns
\n", "