skills/llm/boxed-answer-extraction/SKILL.md
Extract final numeric answers from LaTeX \boxed{} notation in LLM math reasoning output, scanning matches in reverse for robustness
npx skillsauth add wenmin-wu/ds-skills llm-boxed-answer-extractionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Math-reasoning LLMs typically wrap their final answer in \boxed{}. However, chain-of-thought outputs may contain multiple \boxed{} occurrences (intermediate results, corrections). Scan all matches in reverse order and take the last non-empty one — this corresponds to the model's final answer after any self-corrections.
import re
def extract_boxed_answer(text):
pattern = r'\\boxed\{([^{}]*(?:\{[^{}]*\}[^{}]*)*)\}'
matches = re.findall(pattern, text)
if not matches:
return None
for match in reversed(matches):
match = match.strip()
if match:
nums = re.findall(r'-?\d+', match)
if nums:
return int(nums[-1])
return None
answers = [extract_boxed_answer(resp) for resp in responses]
valid = [a for a in answers if a is not None]
\boxed{...} matches via regex\boxed{\frac{1}{2}}\frac, \text) before numeric parsingdata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF