幻觉检测器

v1.0.0

幻觉检测器 - 原创技能。检测AI生成代码中的幻觉内容,包括不存在的API、错误的参数、虚假引用等。适用于代码审查、AI编程辅助、质量保证等场景。

0· 25·0 current·0 all-time

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for 534422530/hallucination-detector.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "幻觉检测器" (534422530/hallucination-detector) from ClawHub.
Skill page: https://clawhub.ai/534422530/hallucination-detector
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install hallucination-detector

ClawHub CLI

Package manager switcher

npx clawhub@latest install hallucination-detector
Security Scan
VirusTotalVirusTotal
Pending
View report →
OpenClawOpenClaw
Benign
high confidence
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.
Assessment
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.

Like a lobster shell, security has layers — review code before you run it.

code-qualityvk970e3wkdbwza9yz4etjvj8frh85peyrdetectionvk970e3wkdbwza9yz4etjvj8frh85peyrhallucinationvk970e3wkdbwza9yz4etjvj8frh85peyrlatestvk970e3wkdbwza9yz4etjvj8frh85peyrverificationvk970e3wkdbwza9yz4etjvj8frh85peyr
25downloads
0stars
1versions
Updated 11h ago
v1.0.0
MIT-0

⚠️ 发布规则

所有发布到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
- 误报率预估: <5%

置信度计算

检测类型基础置信度调整因素
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

Comments

Loading comments...