← Back to Skills Marketplace
534422530

幻觉检测器

by 534422530 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
42
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install hallucination-detector
Description
幻觉检测器 - 原创技能。检测AI生成代码中的幻觉内容,包括不存在的API、错误的参数、虚假引用等。适用于代码审查、AI编程辅助、质量保证等场景。
README (SKILL.md)

⚠️ 发布规则

所有发布到ClawHub的技能必须严格测试,确定没有问题再发布


技能测试验证清单

  • frontmatter格式正确
  • 检测逻辑完整
  • 幻觉类型覆盖全
  • 验证流程明确
  • 无语法错误

Hallucination Detector - 幻觉检测器

原创技能 | 激活词: 检测幻觉 / 验证代码 / 代码审查

核心问题

AI生成的代码可能出现"幻觉":

  • 调用不存在的API
  • 使用错误的参数
  • 引用不存在的文档
  • 混淆相似的库名称
  • 虚构函数签名

幻觉类型分类

类型1: API幻觉

# ❌ 幻觉: 不存在的API
response = requests.get_json(url)  # 应该是 response.json()

# ❌ 幻觉: 错误的方法
list.append_many([1,2,3])  # 应该是 extend()

# ❌ 幻觉: 不存在的参数
df.sort('column', ascending=True)  # pandas 2.x 应该用 by= 参数

类型2: 版本幻觉

# ❌ 幻觉: 版本不兼容
# React 19 不需要 forwardRef 了

# ❌ 幻觉: 过时的API
requests.post(url, data={})  # 应该用 json={}

类型3: 引用幻觉

# ❌ 幻觉: 不存在的文档
# 参见: https://fake-docs-example.com  (虚构链接)

# ❌ 幻觉: 不存在的库
import super_fake_library  # 未发布的库

类型4: 类型幻觉

# ❌ 幻觉: 错误的类型假设
def func(x: str) -> str:
    return x.append('a')  # str没有append方法

# ❌ 幻觉: 类型不匹配
result = await promise.json()  # promise是Promise对象���不是Response

类型5: 逻辑幻觉

# ❌ 幻觉: 不可能的逻辑
if user.is_admin and not user.is_admin:  # 自相矛盾
    return "impossible"

# ❌ 幻觉: 永远为真的条件
if x == x:  # 总是True
    pass

检测策略

1. 静态分析

def static_check(code: str) -> list[Hallucination]:
    issues = []
    
    # 检查不存在的API调用
    for call in extract_api_calls(code):
        if not api_exists(call):
            issues.append(Hallucination(
                type='api',
                location=call.location,
                message=f"API '{call.name}' 不存在"
            ))
    
    # 检查类型错误
    for type_check in extract_type_checks(code):
        if not type_compatible(type_check):
            issues.append(Hallucination(
                type='type',
                location=type_check.location,
                message=f"类型不匹配: {type_check.expected}"
            ))
    
    return issues

2. 引用验证

def verify_references(code: str) -> list[Hallucination]:
    issues = []
    
    for ref in extract_urls_and_docs(code):
        if not url_exists(ref):
            issues.append(Hallucination(
                type='reference',
                location=ref.location,
                message=f"URL不存在或无法访问: {ref.url}"
            ))
    
    for lib in extract_imports(code):
        if not package_exists(lib):
            issues.append(Hallucination(
                type='package',
                location=lib.location,
                message=f"包 '{lib.name}' 不存在"
            ))
    
    return issues

3. 逻辑验证

def logical_check(code: str) -> list[Hallucination]:
    issues = []
    
    for expr in extract_conditions(code):
        if is_contradiction(expr):
            issues.append(Hallucination(
                type='logic',
                location=expr.location,
                message="逻辑矛盾或永真条件"
            ))
    
    return issues

完整检测流程

1. 代码输入
      ↓
2. 静态分析 (API/类型检查)
      ↓
3. 引用验证 (URL/包检查)
      ↓
4. 逻辑验证 (矛盾/永���检查)
      ↓
5. 综合报告
      ↓
6. 修复建议

输出格式

## 幻觉检测报告

### 检测结果: 发现 3 处幻觉 ⚠️

### 幻觉 #1 [高危]
- **类型**: API幻觉
- **位置**: line 15
- **代码**: `response.get_json()`
- **问题**: 方法名错误
- **建议**: 改为 `response.json()`

### 幻觉 #2 [中危]
- **类型**: 版本兼容
- **位置**: line 23
- **代码**: `forwardRef(...)`
- **问题**: React 19 已废弃
- **建议**: 直接使用 ref 作为 prop

### 幻觉 #3 [低危]
- **类型**: 引用幻觉
- **位置**: line 45
- **代码**: `https://docs.example.com/fake`
- **问题**: URL可能不存在
- **建议**: 验证链接或移除

### 置信度评估
- 综合置信度: 0.92
- 误报率预估: \x3C5%

置信度计算

检测类型 基础置信度 调整因素
API检查 0.85 +0.1 静态可验证
版本检查 0.70 +0.1 版本明确
引用检查 0.80 +0.1 可实际验证
逻辑检查 0.75 +0.1 模式明确

集成建议

配合其他技能使用:

配合技能 效果
workflow-verifier 执行前验证代码
karpathy-principles 确保代码简洁可验证
entropy-manager 控制验证流程熵

原创性声明

本技能为原创,融合了:

  • 静态代码分析
  • API签名验证
  • 引用完整性检查
  • 逻辑矛盾检测

作者: laosi 创建日期: 2026-04-28

Usage Guidance
The skill appears coherent and appropriate for code-review use. Before enabling it: 1) confirm how url_exists() / package_exists() will be implemented — those checks typically perform network requests and could fetch remote content; avoid running them on sensitive code unless you trust the network behavior; 2) if you rely on private package registries or internal documentation, ask whether credentials will be required and how they are stored; 3) test the skill on non-sensitive sample code to verify it does not leak contents to external hosts; 4) request documentation from the author about network/timeouts/caching and whether any remote endpoints are logged or contacted. If those questions are answered satisfactorily, the skill is reasonable to use.
Capability Assessment
Purpose & Capability
Name/description describe detecting hallucinations in generated code; the SKILL.md contains static-analysis, reference/package checks, and logic checks that are directly relevant to that goal. The skill does not request unrelated binaries, environment variables, or config paths.
Instruction Scope
Instructions outline static analysis, URL/document verification, package-existence checks, and logical contradiction detection — all in-scope. One operational detail is left unspecified: functions like url_exists() and package_exists() imply network access (checking web URLs and package registries). That is reasonable for reference verification but could involve fetching remote resources or querying external registries; the README does not describe how network queries are performed or whether fetched content is sent elsewhere.
Install Mechanism
No install specification and no code files — this is instruction-only, so nothing is written to disk or installed by the skill itself.
Credentials
The skill declares no required environment variables, credentials, or config paths. The checks described could optionally require access to the network or private registries (which would require credentials), but none are requested here — so permissions requested are proportionate.
Persistence & Privilege
always is false and the skill does not request persistent or elevated privileges. Autonomous invocation is allowed (platform default) and is reasonable for this tool.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install hallucination-detector
  3. After installation, invoke the skill by name or use /hallucination-detector
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
原创技能 - 检测AI生成代码中的幻觉内容
Metadata
Slug hallucination-detector
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is 幻觉检测器?

幻觉检测器 - 原创技能。检测AI生成代码中的幻觉内容,包括不存在的API、错误的参数、虚假引用等。适用于代码审查、AI编程辅助、质量保证等场景。 It is an AI Agent Skill for Claude Code / OpenClaw, with 42 downloads so far.

How do I install 幻觉检测器?

Run "/install hallucination-detector" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is 幻觉检测器 free?

Yes, 幻觉检测器 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does 幻觉检测器 support?

幻觉检测器 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created 幻觉检测器?

It is built and maintained by 534422530 (@534422530); the current version is v1.0.0.

💬 Comments