INNER CODE UNIT · Python

check_expectation

wgpsec/AboutSecurity · scripts/bench-skill.py:195

def check_expectation(output: str, expectation: str) -> bool:
    """
    Check if an expectation is met in the output.

    Supports two formats:
    1. Free-text expectation: "提到了 UNION SELECT 注入"
       → checks if key terms ("UNION", "SELECT") appear in output
    2. Keyword list (pipe-separated): "UNION|union select|联合查询"
       → checks if any keyword appears

    Override with LLM grading for subjective expectations.
    """
    output_lower = output.lower()

    # If expectation contains | separator, treat as keyword alternatives
    if "|" in expectation:
        keywords = [k.strip().lower() for k in expectation.split("|")]
        return any(kw in output_lower for kw in keywords if kw)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…