From c421f19e57d68e0ab7b7232eeebbaefb35512f06 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 10 Dec 2024 13:47:35 -0600 Subject: [PATCH] Throw error instead of warn if tool parameters aren't valid JSON --- chatlas/_openai.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chatlas/_openai.py b/chatlas/_openai.py index 025be4c..3a8b5f4 100644 --- a/chatlas/_openai.py +++ b/chatlas/_openai.py @@ -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 @@ -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(