This document details the evaluation criteria, methods, and examples for all 27 constraint types in the MultiCodeIF benchmark.
Our evaluation covers 9 categories of constraints (27 specific types) with distinct verification approaches:
- Rule-based checks: Static analysis via AST parsing/regex (63% of constraints)
- LLM-based verification: Semantic validation via prompt engineering (37%)
- Hybrid methods: Combined static+neural approaches for complex cases
- Interface Specification
- Environment
- Data Structure
- Algorithm
- Coding Style
- Code Quality
- Scenario
- Code Context
- Exemplar
Evaluation Methods
- Parameter/Return Types: Tree-Sitter + AST parsing & type checking
- Ranges/Cardinality: LLM verification via prompts comparing with human-reference implements
Examples
# Example Rule Check (Return Type)
def validate_return_type(code, expected_type):
tree = ast.parse(code)
for node in ast.walk(tree):
if isinstance(node, ast.Return):
return compare_types(node.value, expected_type)
# Example LLM Check (LLM Prompt)
"""
You are an expert code reviewer. Evaluate whether the following code satisfies the given constraint by comparing it with a reference implementation.
Code Generation Task:
{task}
Constraint:
{constraint}
Reference Implementation:
{reference}
Generated Implementation:
{generated}
Please answer with one of the following:
- YES: if the generated code satisfies the constraint and is functionally similar or equivalent to the reference implementation.
- NO: if the generated code clearly violates the constraint or behaves differently.
Output ONLY YES or NO, no additional information.
"""Evaluation Methods
- Language Type: Use the Guesslang tool
- Language Version: Compile tests with different versions of the language
- Advanced Syntax/Function, Method Invocation/API, Library Usage: Tree-Sitter + AST parsing & Regular matching
- Framework: LLM verification via prompts comparing with human-reference implements
Examples
# API Usage Validation
def validate_library_usage(code, library):
imports = set()
tree = ast.parse(code)
for node in ast.walk(tree):
if isinstance(node, ast.Import):
imports.update(alias.name for alias in node.names)
elif isinstance(node, ast.ImportFrom):
imports.add(node.module)
return library in importsEvaluation Methods
- Data Structure Type: Tree-Sitter + AST parsing & type checking
- Data Structure Scale: Tree-Sitter + AST parsing & Regular matching
- Data Structure Operation: Tree-Sitter + AST parsing +
Function, Method Invocationused inEnvironmentconstraint
Examples
# Stack Operation Validation
def validate_stack_operations(code):
required_methods = {'push', 'pop', 'peek'}
called_methods = set()
tree = ast.parse(code)
for node in ast.walk(tree):
if isinstance(node, ast.Call) and hasattr(node.func, 'attr'):
called_methods.add(node.func.attr)
return required_methods.issubset(called_methods)Evaluation Methods
- Algorithm Type/Time & Space Complexity: LLM verification via prompts comparing with human-reference implements
Evaluation Methods
- Naming Convention: Regular matching
- Indentation Style: Regular matching + String matching
- Brace Style: Regular matching + Strings match by line
- Comment Style: Regular matching
- Declaration Style: LLM verification via prompts comparing with human-reference implements
Examples
# Python Docstring Check
def has_docstring(code):
tree = ast.parse(code)
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
if not ast.get_docstring(node):
return False
return True
# Brace Style Validation
def validate_brace_style(code, style='K&R'):
pattern = r'\s*{\s*$' if style == 'Allman' else r'\)\s*{'
return bool(re.search(pattern, code))Evaluation Methods: LLM verification via prompts comparing with human-reference implements
Evaluation Methods: LLM verification via prompts comparing with human-reference implements
Evaluation Methods: LLM verification via prompts comparing with human-reference implements
Evaluation Methods: LLM verification via prompts comparing with human-reference implements
| Metric | Definition | Use Case |
|---|---|---|
| SSR (Soft Satisfaction Rate) | Percentage of individually satisfied constraints: SSR = 𝟙[sat(c₁)] + 𝟙[sat(c₂)] + ... / n |
Granular per-constraint analysis |
| HSR (Hard Satisfaction Rate) | Binary all-or-nothing score: HSR = 1 if all constraints satisfied |
Strict compliance checking |
- Rule-based Evaluation: All evaluation codes are visible in file rule_based_eval.py
- LLM-based Evaluation: All evaluation codes are visible in file llm_based_eval.py