Skip to content

Commit

Permalink
Throw error instead of warn if tool parameters aren't valid JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Dec 10, 2024
1 parent 590e92a commit c421f19
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions chatlas/_openai.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import json
import warnings
from typing import TYPE_CHECKING, Any, Literal, Optional, cast, overload

from pydantic import BaseModel
Expand Down Expand Up @@ -474,11 +473,12 @@ def _as_turn(
try:
args = json.loads(func.arguments) if func.arguments else {}
except json.JSONDecodeError:
warnings.warn(
raise ValueError(
f"The model's completion included a tool request ({func.name}) "
"with invalid JSON for input arguments: '{func.arguments}'",
InvalidJSONParameterWarning,
stacklevel=2,
"with invalid JSON for input arguments: '{func.arguments}'"
"This can happen if the model hallucinates parameters not defined by "
"your function schema. Try revising your tool description and system "
"prompt to be more specific about the expected input arguments to this function."
)

contents.append(
Expand Down

0 comments on commit c421f19

Please sign in to comment.