PIXELBANKv9.1.0
Menu

Extract the final answer from a chain-of-thought response.

Given an LLM response that contains reasoning steps followed by a final answer, extract just the answer. The final answer is always on the last line that starts with "Answer:" or "Therefore:" or "The answer is".

Input: Multi-line LLM response (read until EOF)

Output: The extracted answer (text after the marker, stripped).

If no answer marker is found, output "NO_ANSWER".

Example:

Input:
Let me think step by step.
First, 2 + 3 = 5.
Then, 5 * 2 = 10.
Answer: 10
Output:
10
Reasoning:
  • The input is read line by line until the end of the file (EOF) is reached.
  • Each line is checked for the presence of answer markers ("Answer:", "Therefore:", or "The answer is") at the start of the line.
  • The last line that starts with an answer marker is identified as "Answer: 10", so the text after the marker is extracted and stripped of any leading/trailing whitespace.
  • The extracted text, 1010, is then output as the final answer.

Constraints:

  • Answer markers (case-insensitive): "Answer:", "Therefore:", "The answer is"
  • Use the LAST matching line if multiple exist
  • Strip whitespace from the extracted answer
  • Output NO_ANSWER if no marker found
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Chain-of-Thought Extractor - Medium | PixelBank