Notebooks
G
Google Gemini
Chain Of Thought Prompting

Chain Of Thought Prompting

promptinggemini-cookbookgemini-apiexamplesgemini
Copyright 2025 Google LLC.
[ ]

Gemini API: Chain of thought prompting

Using chain of thought helps the LLM take a logical and arithmetic approach. Instead of outputting the answer immediately, the LLM uses smaller and easier steps to get to the answer.

[6]

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.

[2]

Additionally, select the model you want to use from the available options below:

[3]
MODEL_ID

Example

Sometimes LLMs can return non-satisfactory answers. To simulate that behavior, you can implement a phrase like "Return the answer immediately" in your prompt.

Without this, the model sometimes uses chain of thought by itself, but it is inconsistent and does not always result in the correct answer.

[4]

5 minutes

To influence this you can implement chain of thought into your prompt and look at the difference in the response. Note the multiple steps within the prompt.

[5]

Here's how to solve the donut problem:

  • Donuts per person per minute: If 5 people make 5 donuts in 5 minutes, then one person makes one donut in 5 minutes (5 donuts / 5 people = 1 donut per person).
  • Donuts by 25 people in 5 minutes: 25 people can make 25 donuts every 5 minutes (25 people * 1 donut/person = 25 donuts).
  • How many 5-minute intervals? To make 100 donuts, it would take four 5-minute intervals (100 donuts / 25 donuts per interval = 4 intervals).
  • Total Time: 4 intervals * 5 minutes/interval = 20 minutes.

Answer: It would take 25 people 20 minutes to make 100 donuts.

Next steps

Be sure to explore other examples of prompting in the repository. Try writing prompts about classifying your own data, or try some of the other prompting techniques such as few-shot prompting.