99from kiln_ai .adapters .errors import (
1010 ErrorWithTrace ,
1111 KilnRunError ,
12- format_user_message ,
12+ format_error_message ,
1313)
1414
1515
@@ -59,21 +59,21 @@ class TestFormatUserMessage:
5959 def test_rate_limit_error (self ):
6060 exc = _make_litellm_error (litellm .RateLimitError )
6161 assert (
62- format_user_message (exc )
62+ format_error_message (exc )
6363 == "Rate limit exceeded. Wait a moment and try again."
6464 )
6565
6666 def test_authentication_error (self ):
6767 exc = _make_litellm_error (litellm .AuthenticationError )
6868 assert (
69- format_user_message (exc )
69+ format_error_message (exc )
7070 == "Authentication with the model provider failed. Check your API key."
7171 )
7272
7373 def test_api_connection_error (self ):
7474 exc = _make_litellm_error (litellm .APIConnectionError )
7575 assert (
76- format_user_message (exc )
76+ format_error_message (exc )
7777 == "Could not connect to the model provider. Check your network connection."
7878 )
7979
@@ -88,7 +88,7 @@ def test_api_connection_error(self):
8888 def test_service_unavailable_family (self , cls ):
8989 exc = _make_litellm_error (cls )
9090 assert (
91- format_user_message (exc )
91+ format_error_message (exc )
9292 == "The model provider is currently unavailable. Try again in a moment."
9393 )
9494
@@ -108,7 +108,7 @@ def test_json_schema_validation_error(self):
108108 )
109109 Exception .__init__ (exc , "schema mismatch" )
110110 assert (
111- format_user_message (exc )
111+ format_error_message (exc )
112112 == "The model's output didn't match the expected format."
113113 )
114114
@@ -117,15 +117,15 @@ def test_too_many_turns(self):
117117 "Too many turns (11). Stopping iteration to avoid using too many tokens."
118118 )
119119 assert (
120- format_user_message (exc ) == "The run exceeded the maximum number of turns."
120+ format_error_message (exc ) == "The run exceeded the maximum number of turns."
121121 )
122122
123123 def test_too_many_tool_calls (self ):
124124 exc = RuntimeError (
125125 "Too many tool calls (31). Stopping iteration to avoid using too many tokens."
126126 )
127127 assert (
128- format_user_message (exc )
128+ format_error_message (exc )
129129 == "The run exceeded the maximum number of tool calls in one turn."
130130 )
131131
@@ -134,7 +134,7 @@ def test_tool_not_available(self):
134134 "A tool named 'foo' was invoked by a model, but was not available."
135135 )
136136 assert (
137- format_user_message (exc )
137+ format_error_message (exc )
138138 == "The model tried to call a tool that isn't available on this task."
139139 )
140140
@@ -143,7 +143,7 @@ def test_parse_arguments(self):
143143 "Failed to parse arguments for tool 'foo' (should be JSON): blah"
144144 )
145145 assert (
146- format_user_message (exc )
146+ format_error_message (exc )
147147 == "The model produced invalid arguments for a tool call."
148148 )
149149
@@ -152,7 +152,7 @@ def test_validate_arguments(self):
152152 "Failed to validate arguments for tool 'foo'. The arguments didn't match..."
153153 )
154154 assert (
155- format_user_message (exc )
155+ format_error_message (exc )
156156 == "The model's tool call arguments didn't match the tool's schema."
157157 )
158158
@@ -161,7 +161,7 @@ def test_reasoning_required(self):
161161 "Reasoning is required for this model, but no reasoning was returned."
162162 )
163163 assert (
164- format_user_message (exc )
164+ format_error_message (exc )
165165 == "The model should have returned reasoning but didn't."
166166 )
167167
@@ -171,29 +171,28 @@ def test_schema_mismatch_value_error(self):
171171 "that JSON didn't meet the schema. Search 'Troubleshooting Structured Data Issues' in our docs for more information."
172172 )
173173 assert (
174- format_user_message (exc )
174+ format_error_message (exc )
175175 == "The model's output didn't match the task's output schema."
176176 )
177177
178- def test_unknown_exception_falls_back_to_str (self ):
178+ def test_unknown_exception_uses_generic_message (self ):
179179 exc = KeyError ("missing_key" )
180- # KeyError's str() wraps in quotes; just assert the key name is present
181- assert "missing_key" in format_user_message (exc )
180+ assert format_error_message (exc ) == "An unexpected error occurred."
182181
183- def test_unknown_exception_type_falls_back_to_str (self ):
182+ def test_unknown_exception_type_uses_generic_message (self ):
184183 class WeirdError (Exception ):
185184 pass
186185
187186 exc = WeirdError ("something odd" )
188- assert format_user_message (exc ) == "something odd "
187+ assert format_error_message (exc ) == "An unexpected error occurred. "
189188
190- def test_runtime_error_without_known_prefix_falls_back (self ):
189+ def test_runtime_error_without_known_prefix_uses_generic_message (self ):
191190 exc = RuntimeError ("something random happened" )
192- assert format_user_message (exc ) == "something random happened "
191+ assert format_error_message (exc ) == "An unexpected error occurred. "
193192
194- def test_value_error_without_schema_hint_falls_back (self ):
193+ def test_value_error_without_schema_hint_uses_generic_message (self ):
195194 exc = ValueError ("just a regular value error" )
196- assert format_user_message (exc ) == "just a regular value error"
195+ assert format_error_message (exc ) == "An unexpected error occurred. "
197196
198197 def test_survives_broken_str (self ):
199198 class BrokenStrError (Exception ):
@@ -202,20 +201,18 @@ def __str__(self):
202201
203202 exc = BrokenStrError ("hidden" )
204203 # Should not raise; should return the generic fallback.
205- assert format_user_message (exc ) == "An unexpected error occurred."
204+ assert format_error_message (exc ) == "An unexpected error occurred."
206205
207- def test_empty_message_falls_back_to_class_name (self ):
206+ def test_empty_message_falls_back_to_generic (self ):
208207 exc = RuntimeError ("" )
209- # RuntimeError with no recognised prefix and empty string → class name
210- # (more useful to the user than a totally generic message).
211- assert format_user_message (exc ) == "RuntimeError"
208+ assert format_error_message (exc ) == "An unexpected error occurred."
212209
213- def test_empty_message_custom_class_uses_class_name (self ):
210+ def test_empty_message_custom_class_uses_generic (self ):
214211 class WeirdError (Exception ):
215212 pass
216213
217214 exc = WeirdError ("" )
218- assert format_user_message (exc ) == "WeirdError "
215+ assert format_error_message (exc ) == "An unexpected error occurred. "
219216
220217
221218class TestKilnRunError :
0 commit comments