[BFCL] resolve_ast_by_type decodes every unary operator as negation, so +3 and ~3 are both read as -3
berkeley-function-call-leaderboard/bfcl_eval/model_handler/utils.py:333-334 (HEAD 6ea5797, same as current main):
elif isinstance(value, ast.UnaryOp):
output = -value.operand.valueThis branch never reads value.op. Every ast.UnaryOp (+x, -x, ~x, not x) is decoded as arithmetic negation of a bare constant. -5 comes out right, and that is the only case the line handles. +5, ~5 and not True all decode to negative numbers. If the operand is not a plain constant (-(2+3), - -5, -y), decoding raises AttributeError, because the operand node has no .value.
ast_parse reaches this code through resolve_ast_call. ast_parse is used by default_decode_ast_prompting and default_decode_execute_prompting, which serve base_oss_handler and the prompt-mode paths of the claude, gemini, mistral, nemotron, nvidia, openai_completion and openai_response handlers. ast_parse is also called directly from decode_ast / decode_execute in api_inference/gorilla.py and api_inference/nexus.py. local_inference/minicpm_fc.py:319 calls resolve_ast_call itself, which then reaches resolve_ast_by_type. No test in the repository covers this branch. Function-calling handlers that receive JSON arguments are not affected, because +5 is not valid JSON.
Measured
Method: the source text of ast_parse, resolve_ast_call, resolve_ast_by_type, default_decode_ast_prompting, default_decode_execute_prompting, decoded_output_to_execution_list and parse_nested_value was extracted from utils.py. The source text of eval_checker/ast_eval/ast_checker.py was extracted with its import statements removed. All of it was exec'd in a plain Python process. Language, ReturnFormat and MODEL_CONFIG_MAPPING were stubbed, and the Java/JS converters were set to None and the Java/JavaScript call parsers replaced with functions that raise, since the Python-language path never touches them. No repository module was imported. The inputs are the real rows from data/BFCL_v4_*.json and data/possible_answer/BFCL_v4_*.json.
Decoder only:
| model text | decoded | correct value |
|---|---|---|
f(x=-5) (control) |
-5 |
-5 |
f(x=5) (control) |
5 |
5 |
f(x=+5) |
-5 |
5 |
f(x=+2.5) |
-2.5 |
2.5 |
f(x=~5) |
-5 |
-6 |
f(x=not True) |
-1 |
False |
f(x=[-1, +2]) |
[-1, -2] |
[-1, 2] |
f(x=- -5) |
AttributeError: 'UnaryOp' object has no attribute 'value' |
5 |
f(x=-(2+3)) |
AttributeError: 'BinOp' object has no attribute 'value' |
-5 |
f(x=-y) |
AttributeError: 'Name' object has no attribute 'value' |
(not a number) |
End to end through ast_checker on real gold rows: simple_python_3 (prompt: "coefficients a=1, b=-3, c=2", gold {"a": [1], "b": [-3], "c": [2]}) and simple_python_1 (prompt: "factorial of 5", gold number: [5]).
| id | model text | decoded | valid |
expected |
|---|---|---|---|---|
| simple_python_3 | algebra.quadratic_roots(a=1, b=-3, c=2) (control, must pass) |
b=-3 |
True | True |
| simple_python_3 | algebra.quadratic_roots(a=1, b=3, c=2) (control, must fail) |
b=3 |
False | False |
| simple_python_3 | algebra.quadratic_roots(a=1, b=+3, c=2) |
b=-3 |
True | False (+3 is 3) |
| simple_python_3 | algebra.quadratic_roots(a=1, b=~3, c=2) |
b=-3 |
True | False (~3 is -4) |
| simple_python_1 | math.factorial(number=5) (control, must pass) |
5 |
True | True |
| simple_python_1 | math.factorial(number=-5) (control, must fail) |
-5 |
False | False |
| simple_python_1 | math.factorial(number=+5) |
-5 |
False | True |
Execute path (prompt-mode multi-turn), using an invented function name: default_decode_execute_prompting("[transfer_funds(amount=+50)]") returns ['transfer_funds(amount=-50)']. The same call with amount=50 returns amount=50.
Sweep over the gold data in 8 Python-language categories: simple_python, multiple, parallel, parallel_multiple, live_simple, live_multiple, live_parallel and live_parallel_multiple. For each gold entry, every call was rendered as source text using the first non-empty accepted value of each parameter, then decoded and checked. 2300 of 2351 entries validate as rendered, and the other 51 were excluded. Numeric parameters were then changed one at a time:
| population | change | accepted / rejected |
|---|---|---|
| 27 top-level numeric params whose accepted values are all negative | write +abs(v) |
accepted 27 of 27 |
| the same 27 | write plain abs(v) (control) |
rejected 27 of 27 |
| 2400 top-level numeric params whose accepted values are all positive | write +v |
rejected 2400 of 2400 |
Examples among the 27: simple_python_3 (b), simple_python_5 (b, c), simple_python_15 (start_x), simple_python_29 (gravity, gold -9.81), multiple_11 (c). Numbers nested inside lists and dicts pass through the same branch and are not counted here.
How often any model actually emits a unary + or ~ was not measured. The defect in the decoder is deterministic, and the numbers above measure how much of the data it can affect.
Consequence
- A reply that gets the sign wrong and writes it with an explicit
+or~is scored correct for every gold parameter whose only accepted values are negative (27 in the current data). - A reply that writes the correct positive value with an explicit
+is scored wrong, for any numeric parameter. - In prompt-mode multi-turn runs the same decode feeds the executor.
f(x=+N)runs asf(x=-N), and the state diverges from what the model wrote. - Non-constant operands (
-(2+3),- -5) raise, and a raised decode error is scored as a failed call in the AST categories.
Suggested fix
Resolve the operand recursively and apply the operator the node names. The List, Dict and Tuple branches of the same function already recurse this way. operator is already imported at the top of utils.py, and the neighbouring BinOp branch already evaluates a full expression instead of assuming a constant. The same file has had earlier value-decoding fixes of this kind (CHANGELOG.md:342, PR #660, for parse_nested_value).
_UNARY_OPS = {
ast.UAdd: operator.pos,
ast.USub: operator.neg,
ast.Invert: operator.invert,
ast.Not: operator.not_,
}
...
elif isinstance(value, ast.UnaryOp):
output = _UNARY_OPS[type(value.op)](resolve_ast_by_type(value.operand))Applied to the extracted function text, this gives +5 -> 5, ~5 -> -6, not True -> False, - -5 -> 5, -(2+3) -> -5, [-1, +2] -> [-1, 2], and -5 stays -5. In the sweep above, 0 of the 27 +abs(v) rewrites are accepted and 2399 of the 2400 +v rewrites are accepted. The remaining one (parallel_multiple_12, permeability, gold ["", 0.1]) is also rejected when written as plain 0.1, because the function schema does not declare that parameter. The operator is not the cause. -y still raises (TypeError instead of AttributeError), so it is still a decode failure. One side effect: not y now decodes to False instead of raising, because a bare name resolves to its identifier string.
Source: ShishirPatil/gorilla