Commit 3426cff
committed
Make Anthropic structured extraction reliable + classify None failures
doc_extract_query_task with anthropic:claude-sonnet-4-6 was failing
~85% of cells on the LegalBench-RAG benchmark with the canonical
"extraction returned None" message. The captured Datacell.llm_call_log
showed Claude's last assistant message was always text + tool_use parts
and never a final structured response — pydantic-ai's structured-response
runner treated this as no result and returned None. The same prompts on
gpt-4o-mini / gpt-4o produced 0-3% failure rate.
Three coordinated changes:
1. Strengthen the structured-extraction system prompt (all three
_build_structured_system_prompt overrides in pydantic_ai_agents.py)
to explicitly tell the agent it MUST commit to the final structured
response by calling the result tool after gathering information.
Wording is universal — harmless for OpenAI, necessary for Claude.
2. Pass output_retries=3 to PydanticAIAgent for structured runs (was
pydantic-ai's default of 1) so the loop has room to retry the
final-result tool call when the model fails to commit on the first
pass. Add an _is_anthropic_model() helper and force temperature=0
for structured runs against Anthropic models when the caller did
not pin a temperature — Claude is reluctant to commit at non-zero
temperatures.
3. Classify why doc_extract_query_task got None back, instead of
reporting a single ambiguous error. New _classify_none_result()
helper inspects the captured pydantic-ai message log and returns
one of agent_committed_none (legitimate), no_final_response
(integration failure — the canonical Anthropic mode), tool_loop_no_output
(integration failure), or unknown. The Datacell.stacktrace records
failure_mode=<classification> plus a human-readable message, so
operators can grep failure_mode= to separate "data not present"
outcomes from pipeline bugs.
Closes #13811 parent f40e91f commit 3426cff
4 files changed
Lines changed: 365 additions & 17 deletions
File tree
- opencontractserver
- llms/agents
- tasks
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
106 | 125 | | |
107 | 126 | | |
108 | 127 | | |
| |||
496 | 515 | | |
497 | 516 | | |
498 | 517 | | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
499 | 524 | | |
500 | 525 | | |
501 | 526 | | |
502 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
503 | 532 | | |
504 | 533 | | |
505 | | - | |
| 534 | + | |
| 535 | + | |
506 | 536 | | |
507 | 537 | | |
508 | 538 | | |
| |||
1311 | 1341 | | |
1312 | 1342 | | |
1313 | 1343 | | |
| 1344 | + | |
| 1345 | + | |
1314 | 1346 | | |
1315 | 1347 | | |
1316 | 1348 | | |
1317 | 1349 | | |
1318 | 1350 | | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1319 | 1365 | | |
1320 | 1366 | | |
1321 | 1367 | | |
| |||
1346 | 1392 | | |
1347 | 1393 | | |
1348 | 1394 | | |
1349 | | - | |
| 1395 | + | |
1350 | 1396 | | |
1351 | 1397 | | |
1352 | 1398 | | |
1353 | 1399 | | |
1354 | 1400 | | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
1355 | 1404 | | |
1356 | 1405 | | |
1357 | 1406 | | |
| |||
1960 | 2009 | | |
1961 | 2010 | | |
1962 | 2011 | | |
1963 | | - | |
1964 | | - | |
1965 | | - | |
1966 | | - | |
1967 | | - | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
1968 | 2024 | | |
1969 | 2025 | | |
1970 | 2026 | | |
| |||
2465 | 2521 | | |
2466 | 2522 | | |
2467 | 2523 | | |
2468 | | - | |
2469 | | - | |
2470 | | - | |
2471 | | - | |
2472 | | - | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
2473 | 2536 | | |
2474 | 2537 | | |
2475 | 2538 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
19 | 130 | | |
20 | 131 | | |
21 | 132 | | |
| |||
340 | 451 | | |
341 | 452 | | |
342 | 453 | | |
343 | | - | |
344 | | - | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
345 | 461 | | |
346 | | - | |
| 462 | + | |
| 463 | + | |
347 | 464 | | |
| 465 | + | |
348 | 466 | | |
349 | 467 | | |
350 | | - | |
351 | | - | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
352 | 471 | | |
353 | 472 | | |
354 | 473 | | |
| |||
0 commit comments