Commit a574a9f
fix: handle empty or missing tool-call arguments in from_openai_dict_format
`ChatMessage.from_openai_dict_format` did `json.loads(tc["function"]["arguments"])`,
assuming `arguments` is always present and a valid JSON string. Zero-argument tool
calls from OpenAI-compatible servers (vLLM, llama.cpp, Ollama, LM Studio, ...)
send an empty string, null, or omit the key entirely, which raised
`json.JSONDecodeError` or `KeyError` — even though the method docstring courts
these 'shallow OpenAI-compatible APIs'. The message validator only checks that a
`function` field exists, so nothing guarded this.
Treat empty/null/missing arguments as an empty dict, leaving valid-JSON parsing
unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent acc9e58 commit a574a9f
3 files changed
Lines changed: 33 additions & 1 deletion
File tree
- haystack/dataclasses
- releasenotes/notes
- test/dataclasses
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
795 | 798 | | |
796 | 799 | | |
797 | 800 | | |
798 | | - | |
| 801 | + | |
799 | 802 | | |
800 | 803 | | |
801 | 804 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
966 | 966 | | |
967 | 967 | | |
968 | 968 | | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
969 | 990 | | |
970 | 991 | | |
971 | 992 | | |
| |||
0 commit comments