Registry / llm-agents / math-verify

math-verify

JSON →
library0.9.0pypypi✓ verified 23d ago

Math-Verify is a robust Python library from HuggingFace, currently at version 0.9.0, designed for evaluating Large Language Model outputs in mathematical tasks. It provides sophisticated capabilities for parsing and verifying mathematical expressions, including LaTeX and plain numerical formats. The library supports complex features like set theory, equation/inequality comparison, and advanced normalization, aiming to offer higher accuracy in assessing LLM performance on math problems by moving beyond strict format requirements and inflexible comparison logic. It maintains an active development and release cadence.

pip install math-verify
INSTALL
IMPORT
SIG · MATH-VERIFY
M
math-verify
llm-agentspythonv0.9.0
Install
6.5s avg
Import
1265ms
Disk
95MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 5.95s
py 3.11
✓ —
✓ 6s
py 3.12
✓ —
✓ 6.95s
py 3.13
✓ —
✓ 7.1s
py 3.9
✕ build_error
✕ build_error
95MB installed
● package 95MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from math_verify import parse
verify
from math_verify import verify
LatexExtractionConfig
from math_verify import LatexExtractionConfig
ExprExtractionConfig
from math_verify import ExprExtractionConfig
StringExtractionConfig
from math_verify import StringExtractionConfig

This quickstart demonstrates how to use `parse` to extract mathematical expressions from strings (both LaTeX and plain expressions) and `verify` to check for mathematical equivalence. It highlights the use of `ExtractionConfig` classes and illustrates the default asymmetric behavior for comparing intervals and inequalities.

from math_verify import parse, verify, LatexExtractionConfig, ExprExtractionConfig # Define extraction configurations extraction_configs = [LatexExtractionConfig(), ExprExtractionConfig()] # Parse the gold standard answer (e.g., from a dataset) gold_answer_text = "${1,3} \cup {2,4}$" gold_parsed = parse(gold_answer_text, extraction_config=extraction_configs) # Parse the LLM generated answer llm_answer_text = "${1,2,3,4}$" llm_parsed = parse(llm_answer_text, extraction_config=extraction_configs) # Verify if the LLM's answer is mathematically equivalent to the gold standard is_correct = verify(gold_parsed, llm_parsed) print(f"Gold: {gold_answer_text} -> {gold_parsed}") print(f"LLM: {llm_answer_text} -> {llm_parsed}") print(f"Are answers equivalent? {is_correct}") # Another example with an inequality and asymmetric comparison behavior gold_ineq = parse("1 < x < 2") llm_interval = parse("(1,2)") print(f"\nGold (inequality): {gold_ineq}") print(f"LLM (interval): {llm_interval}") print(f"Are they equivalent (default)? {verify(gold_ineq, llm_interval)}") # To allow symmetric comparison (e.g., if gold is interval and pred is inequality) gold_interval = parse("(1,2)") llm_ineq = parse("1 < x < 2") print(f"\nGold (interval): {gold_interval}") print(f"LLM (inequality): {llm_ineq}") print(f"Are they equivalent (default)? {verify(gold_interval, llm_ineq)}") print(f"Are they equivalent (allow_set_relation_comp=True)? {verify(gold_interval, llm_ineq, allow_set_relation_comp=True)}")
Debug
Known issues
breakingAs of version 0.5.0, `math-verify` replaced the direct use of `sympy.FiniteSet` with `FiniteSet` from `latex2sympy2_extended.sets`. If your code directly interacted with `sympy.FiniteSet` objects in conjunction with `math-verify`'s internal set handling, this change might break compatibility or lead to unexpected behavior.
fix
Review any code that explicitly creates or manipulates `sympy.FiniteSet` objects intended for use with `math-verify`. Consider adapting to `latex2sympy2_extended.sets.FiniteSet` or ensuring compatibility through conversion if necessary.
affects: >=0.5.0
deprecatedThe `equations` parameter in `NormalizationConfig` was deprecated in version 0.6.0. Its functionality is now handled internally by the parser.
fix
Remove the `equations` parameter from your `NormalizationConfig` instances. The parser will automatically manage equation handling.
affects: >=0.6.0
gotchaThe `verify` function has an intentional asymmetric behavior when comparing interval-like expressions (e.g., `(1,2)`) and inequality-like expressions (e.g., `1 < x < 2`). By default, `verify` might return `True` for `1 < x < 2` (gold) vs. `(1,2)` (prediction), but `False` for `(1,2)` (gold) vs. `1 < x < 2` (prediction). This design prevents models from simply returning the input inequality without solving it.
fix
If symmetric comparison is desired, pass `allow_set_relation_comp=True` to the `verify` function. For example: `verify(gold, answer, allow_set_relation_comp=True)`.
affects: All versions
gotchaAs of version 0.6.2, the parsing timeout mechanism was changed from being per-extraction to global. This means that a single long input with multiple embedded expressions might exhaust the global timeout, even if individual extractions would have completed within their own (now defunct) per-extraction limits.
fix
Monitor parsing times for very long or complex inputs. Adjust the overall `parsing_timeout` parameter in your `ExtractionConfig` or consider pre-processing excessively long inputs if timeouts become frequent.
affects: >=0.6.2
gotchaIn version 0.8.0, the default logging verbosity was reduced, and internal errors are now logged at the debug level by default. This means you might not see parsing or verification errors in standard log outputs unless `raise_on_error` is set to `True` or logging is configured to show debug messages.
fix
To ensure internal errors are propagated as exceptions, set `raise_on_error=True` when calling `parse` or `verify`. Alternatively, configure your Python logging to display messages at `DEBUG` level for the `math_verify` module.
affects: >=0.8.0
gotchaThe `verify` function's behavior for lists containing a mix of SymPy expressions and strings is optimized for inputs originating from the `parse` function. Directly constructing lists (e.g., `[sympy.Number(0), '0']`) and passing them to `verify` might lead to unexpected `False` results, especially when a SymPy expression on one side should logically match a string on the other.
fix
Always use the `parse` function to process both gold and prediction answers before passing their outputs to `verify`. Avoid manually creating mixed lists of SymPy objects and strings for direct verification.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'math_verify'
The 'math-verify' package is not installed in the Python environment.
fix
Install the package using pip: `pip install math-verify`.
ImportError: cannot import name 'verify_math' from 'math_verify'
The function 'verify_math' does not exist in the 'math_verify' module.
fix
Check the module's documentation for the correct function name and update the import statement accordingly.
TypeError: 'NoneType' object is not callable
A function from 'math_verify' is returning None, possibly due to incorrect input or usage.
fix
Ensure that the inputs to the function are correct and that the function is used as per the library's guidelines.
AttributeError: module 'math_verify' has no attribute 'parse'
The 'parse' function (or 'verify') was not directly imported from the 'math_verify' module, likely due to using `import math_verify` and then attempting `math_verify.parse()`.
fix
Change your import statement to `from math_verify import parse, verify` to directly import the functions.
Fail to parse and verify answer in XXX
The input mathematical expression (e.g., LaTeX string) is not in a format that 'math-verify' can successfully parse or extract, often due to missing or incorrect delimiters/environments.
fix
Ensure mathematical expressions are correctly formatted. For LaTeX, make sure expressions are enclosed in supported environments like `\boxed{...}`, `$$...$$`, or `\[...\]`.
Upgrade
Version history
0.9.0latest on PyPI · released Jan 10, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.10 or newer.
antlr4-python3-runtimerequiredCore dependency for parsing; multiple versions (4.13.2, 4.11.0, 4.9.3) are supported via extras, and specifying one is recommended.
latex2sympy2_extendedrequiredUsed for LaTeX parsing and conversion to SymPy expressions.
sympyrequiredUnderlying symbolic mathematics library for expression comparison.
Agent activity
46 hits · last 30 days
node
44
OpenAI (training)
1
Resources
math-verify — pip install math-verify · libregistry