Skip to content

Add NumGuardTool: verify a number before an agent asserts it - #6630

Open
ipezygj wants to merge 2 commits into
crewAIInc:mainfrom
ipezygj:add-numguard-tool
Open

Add NumGuardTool: verify a number before an agent asserts it#6630
ipezygj wants to merge 2 commits into
crewAIInc:mainfrom
ipezygj:add-numguard-tool

Conversation

@ipezygj

@ipezygj ipezygj commented Jul 24, 2026

Copy link
Copy Markdown

NumGuardTool — verify a number before an agent asserts it

Adds a tool (under lib/crewai-tools) that routes a numeric claim to the statistical check that most directly tests it and returns whether it survives, plus an honest verdict. It lets a crew gate a backtest Sharpe (Deflated Sharpe Ratio), an A/B accuracy gap, a cherry-picked subset win, or an LLM-judge preference before reporting it as real.

Backed by the open-source numguard library.

Usage

from crewai_tools import NumGuardTool
tool = NumGuardTool()
tool.run(kind="backtest", params={"sr": 0.12, "T": 250, "n_trials": 100})
# {"survives": false, "verdict": "... does NOT survive deflation ...", ...}

Follows the repo conventions

  • src/crewai_tools/tools/numguard_tool/ with numguard_tool.py + README.md
  • Registered alphabetically (import + __all__) in both tools/__init__.py and crewai_tools/__init__.py
  • Optional dependency via package_dependencies = ["numguard"] (same pattern as ArxivPaperTool) — no hard dependency added to the package
  • _run fails soft (returns a message) if numguard isn't installed or the claim is malformed

Note

  • tool.specs.json is a generated artifact (generate_tool_specs.py) that imports the full tool suite; I wasn't able to run the full-suite generator in my environment, so I've left tool.specs.json for regeneration by the maintainers/CI (python -m crewai_tools.generate_tool_specs). Happy to update if preferred.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

NumGuardTool is added with a Pydantic input schema, dynamic numguard verification, error handling, and JSON output. It is exported from both package namespaces, with documentation covering installation, supported inputs, invocation, agent integration, and responses.

NumGuard tool integration

Layer / File(s) Summary
Tool contract and verification runtime
lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py
Defines NumGuardToolInput and implements NumGuardTool execution through numguard.guard.check, including missing-dependency handling, exception handling, and normalized JSON results.
Public exports and usage documentation
lib/crewai-tools/src/crewai_tools/__init__.py, lib/crewai-tools/src/crewai_tools/tools/__init__.py, lib/crewai-tools/src/crewai_tools/tools/numguard_tool/README.md
Exports NumGuardTool from both package namespaces and documents supported claims, parameters, usage, agent wiring, and response structure.

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant NumGuardTool
  participant NumGuard
  Agent->>NumGuardTool: run(kind, params)
  NumGuardTool->>NumGuard: guard.check(kind, **params)
  NumGuard-->>NumGuardTool: verdict payload
  NumGuardTool-->>Agent: JSON result
Loading

Suggested reviewers: lorenzejay

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding NumGuardTool for numeric claim verification.
Description check ✅ Passed The description is directly about the new NumGuardTool, its usage, and integration details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py (1)

18-27: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the public input model.

NumGuardToolInput is part of the tool contract but has no class docstring. Add a short model-level docstring; keep the field descriptions for schema generation.

As per coding guidelines, public APIs and complex logic in Python code must be documented.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py`
around lines 18 - 27, Add a concise class-level docstring to the public
NumGuardToolInput model describing its purpose and role as the NumGuard tool
input contract. Preserve the existing kind and params field descriptions
unchanged for schema generation.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py`:
- Around line 55-62: Update the failure handling in NumGuardTool’s verification
flow to return JSON for both missing-dependency and malformed-claim paths,
matching the documented error envelope. Clearly mark failures as unverified so
they cannot be confused with a verified result where survives is false, while
preserving the existing success response shape and error details.
- Around line 51-54: Update the dependency import and invocation in the NumGuard
tool to use the supported top-level numguard.verify_claim API instead of
numguard.guard.check. Preserve the existing ImportError response for missing
numguard and pass the tool’s claim input through the documented API.

---

Nitpick comments:
In `@lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py`:
- Around line 18-27: Add a concise class-level docstring to the public
NumGuardToolInput model describing its purpose and role as the NumGuard tool
input contract. Preserve the existing kind and params field descriptions
unchanged for schema generation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41d1c982-177e-4e07-becb-90ef3a99fee2

📥 Commits

Reviewing files that changed from the base of the PR and between b14d36b and 7cd5d8b.

📒 Files selected for processing (4)
  • lib/crewai-tools/src/crewai_tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/__init__.py
  • lib/crewai-tools/src/crewai_tools/tools/numguard_tool/README.md
  • lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py

Comment on lines +51 to +54
try:
from numguard.guard import check
except ImportError:
return "numguard is not installed. Run: pip install numguard"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

python - <<'PY'
from numguard import verify_claim

result = verify_claim("backtest", sr=0.12, T=250, n_trials=100)
assert isinstance(result, dict)
assert "survives" in result
print(result)
PY

Repository: crewAIInc/crewAI

Length of output: 275


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file context =="
sed -n '1,120p' lib/crewai-tools/src/crewapi_tools/tools/numguard_tool/numguard_tool.py 2>/dev/null || sed -n '1,120p' lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py

echo
echo "== locate numguard_tool.py =="
fd -a 'numguard_tool\.py$' . || true

echo
echo "== package metadata clues for numguard =="
rg -n "numguard|numguard_tool|guard\.check|verify_claim|from numguard" pyproject.toml requirements* setup.py setup.cfg poe.lock pnpm-lock . 2>/dev/null | head -120 || true

echo
echo "== installed numguard probe =="
python3 - <<'PY'
import subprocess, json, sys
for pkg in ["numguard"]:
    r = subprocess.run([sys.executable, "-m", "pip", "show", pkg], capture_output=True, text=True)
    print(pkg, "available:", r.returncode == 0)
    if r.returncode == 0:
        print(r.stdout.strip())
    print(r.stderr.strip())
PY

Repository: crewAIInc/crewAI

Length of output: 4064


🌐 Web query:

numguard python package verify_claim import numguard.guard check

💡 Result:

There is no single Python package that combines the specific import numguard.guard and a verify_claim function as described. Several different projects have names similar to or associated with the term "numguard" or claim-verification functionality, which may be causing confusion. 1. NumGuard (Numeric Integrity): The term "NumGuard" refers to a numeric integrity utility used in the doc2dataset project [1][2][3]. It is primarily implemented in Rust [4][2], with Python bindings available via the three_dcf_py crate [1][3]. It is used for tracking and hashing numeric data in document pipelines to detect corruption [2][3], rather than acting as a general-purpose claim verification library. 2. numguard (PyPI package): There is a Python package named numguard on PyPI (version 0.1.1) [5]. It includes functions such as verify_claim, issue_receipt, and verify_receipt [5]. Based on its documentation, this package is designed for verifying statistical claims (e.g., related to the "Deflated Sharpe Ratio") and handling cryptographically signed receipts for agentic workflows [5]. It is not related to the "NumGuard" numeric integrity tool mentioned above. 3. NuGuard (Security Suite): There is also a distinct, unrelated project called nuguard (NuGuard AI), which is an AI application security toolkit used for SBOM generation, red-teaming, and behavioral validation [6][7][8]. It does not use the import numguard.guard. If you are working with the numguard package from PyPI, the correct imports are typically from numguard import verify_claim [5]. If you are looking for claim verification in other agentic contexts, other libraries such as multimodal-evidence-sdk (which also provides a verify_claim function) [9] or verity-guard [10] offer similar but distinct functionality.

Citations:


🌐 Web query:

PyPI numguard 0.1.1 source __init__.py verify_claim

💡 Result:

In the context of the PyPI package numguard (version 0.1.1), the function verify_claim is a tool used for validating statistical claims, such as those related to backtesting performance (e.g., Deflated Sharpe Ratio) [1][2]. It is designed to be used in conjunction with other functions like issue_receipt and verify_receipt to create and verify signed, tamper-evident records of claim verdicts [1][2]. Example usage from the numguard library: from numguard import verify_claim, issue_receipt, verify_receipt, keypair priv, pub = keypair result = verify_claim("backtest", sr=0.12, T=250, n_trials=100) receipt = issue_receipt(result, priv, pub) verify_receipt(receipt) # Returns True if the signed receipt is valid Note that while there is an Elixir library called Guardian that also defines a verify_claim callback for token authentication [3][4][5], it is distinct from the Python package numguard [1][2]. The mention of init.py typically refers to the package's entry point where these functions are exposed for import [1][2].

Citations:


🌐 Web query:

raw github ipezygj numguard master numguard __init__.py verify_claim

💡 Result:

The Python package numguard by ipezygj, available on PyPI [1], is a verification layer designed for the AI agent economy [1]. It functions as an agent-callable MCP (Model Context Protocol) server [1] that allows agents to check numeric claims, such as eval scores or backtest results, before asserting them [1]. Regarding the specific reference to a verify_claim function in numguard, the numguard package is primarily structured as an MCP server [1]. While the project is intended to provide tools for agents to verify numbers [1], the specific implementation of verify_claim (or similar tools) within the Python codebase follows the MCP architecture. Agents interact with these verification functions by calling them through the MCP interface [1]. It is important to distinguish this Python-based numguard (created by ipezygj) [1] from the "NumGuard" numeric integrity system found in the 3DCF-Labs/doc2dataset project [2]. The 3DCF-Labs implementation is a Rust-native system [2] that stores NumGuard records as structs containing numeric coordinates and SHA-1 hashes to detect data corruption in documents [3][4]. These are two distinct projects that happen to share the same name [1][2]. For the ipezygj/numguard library, you can install and use it as follows [1]: pip install git+https://github.com/ipezygj/numguard python -m numguard.mcp_server Agents can then invoke verification tools exposed by this server to obtain signed receipts for their numeric claims [1]. For specific API details, including the exact naming of functions like verify_claim, you should consult the source code in the numguard/init.py file within the ipezygj/numguard GitHub repository.

Citations:


🌐 Web query:

github ipezygj numguard numguard .py numguard __init__.py verify_claim

💡 Result:

The term NumGuard appears in two distinct, unrelated technical contexts: a numeric integrity tool within a document processing pipeline, and an AI evaluation/verification library. 1. NumGuard (Numeric Integrity): This is a component of the 3DCF/doc2dataset pipeline [1][2][3]. It is designed to maintain data accuracy when converting financial or legal documents into training data [4][2]. It extracts numbers from documents, computes SHA-1 hashes (stored in a NumGuard record containing coordinates and units), and tracks them to detect numeric corruption [3][5]. It is implemented in Rust with Python and Node.js bindings [1][2]. 2. numguard (AI Evaluation): This is a Python library (available on PyPI) created by user ipezygj [6]. It functions as an Model Context Protocol (MCP) server designed to verify AI evaluation claims, such as benchmark scores, leaderboard rankings, and LLM-judge verdicts [6]. It builds upon the evalgate library and provides tools to check for statistical artifacts like multiple-comparisons errors, judge bias, and overfitting (e.g., via the Deflated Sharpe Ratio) [6]. The function verify_claim (or similar verification tools like verify_backtest) is part of its MCP interface, allowing AI agents to perform integrity checks before trusting or publishing an evaluation result [6]. Note: Do not confuse these with the unrelated project NuGuard (nuguard), which is an AI application security and red-teaming toolkit [7].

Citations:


🌐 Web query:

site:github.com/ipezygj/numguard "numguard.guard" "verify_claim" "__init__"

💡 Result:

I found the repo, but I didn’t find any matches for numguard.guard, verify_claim, or __init__ in the GitHub page contents I could access. The repository README does show verify_claim as part of its public API example, though. (github.com)

If you want, I can dig further into the actual source files in the repo.

Citations:


Call the numguard API by its real name.

The package exposes verify_claim top-level use; from numguard.guard import check is not part of the supported API, so the import fails before the tool can even test the installed-dependency path. Import and call the documented verify_claim API instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py`
around lines 51 - 54, Update the dependency import and invocation in the
NumGuard tool to use the supported top-level numguard.verify_claim API instead
of numguard.guard.check. Preserve the existing ImportError response for missing
numguard and pass the tool’s claim input through the documented API.

Comment on lines +55 to +62
try:
verdict = check(kind, **(params or {}))
except Exception as e:
logger.error(f"NumGuardTool error: {e}")
return f"Could not verify claim '{kind}': {e}"
survives = bool(verdict.get("survives"))
line = verdict.get("verdict") or ("survives" if survives else "flagged")
return json.dumps({"survives": survives, "verdict": line, "detail": verdict}, default=str)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Keep failure responses in the documented JSON shape.

Success returns JSON, but missing dependencies and malformed claims return plain text. This contradicts README.md line 54 and forces consumers to special-case errors. Return a consistent JSON error envelope for both failure paths, clearly distinguishing “unverified” from a verified survives: false result.

🧰 Tools
🪛 ast-grep (0.44.1)

[info] 61-61: use jsonify instead of json.dumps for JSON output
Context: json.dumps({"survives": survives, "verdict": line, "detail": verdict}, default=str)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/crewai-tools/src/crewai_tools/tools/numguard_tool/numguard_tool.py`
around lines 55 - 62, Update the failure handling in NumGuardTool’s verification
flow to return JSON for both missing-dependency and malformed-claim paths,
matching the documented error envelope. Clearly mark failures as unverified so
they cannot be confused with a verified result where survives is false, while
preserving the existing success response shape and error details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant