Skip to content

Commit cc56b29

Browse files
fix: Defined enable_challenge in prompt-service for error handling (#1111)
* fix: Defined enable_challenge in prompt-service correctly to propagate errors * fix: Logged JSON parsing errors to user * minor: Added truncated container name to logs --------- Co-authored-by: Gayathri <142381512+gaya3-zipstack@users.noreply.github.com>
1 parent 019ab7f commit cc56b29

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

prompt-service/src/unstract/prompt_service/main.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def prompt_processor() -> Any:
101101
if not payload:
102102
raise NoPayloadError
103103
tool_settings = payload.get(PSKeys.TOOL_SETTINGS, {})
104+
enable_challenge = tool_settings.get(PSKeys.ENABLE_CHALLENGE, False)
104105
# TODO: Rename "outputs" to "prompts" in payload
105106
prompts = payload.get(PSKeys.OUTPUTS, [])
106107
tool_id: str = payload.get(PSKeys.TOOL_ID, "")
@@ -277,7 +278,6 @@ def prompt_processor() -> Any:
277278
metadata=metadata,
278279
execution_source=execution_source,
279280
)
280-
# TODO: Handle metrics for line-item extraction
281281
continue
282282
except APIError as e:
283283
app.logger.error(
@@ -494,12 +494,24 @@ def prompt_processor() -> Any:
494494
)
495495
structured_output[output[PSKeys.NAME]] = json.loads(answer)
496496
except JSONDecodeError as e:
497-
app.logger.info(
498-
f"JSON format error : {answer}", LogLevel.ERROR
497+
err_msg = (
498+
f"Error parsing response (to json): {e}\n"
499+
f"Candidate JSON: {answer}"
499500
)
500-
app.logger.info(
501-
f"Error parsing response (to json): {e}",
502-
LogLevel.ERROR,
501+
app.logger.info(err_msg, LogLevel.ERROR)
502+
# TODO: Format log message after unifying these types
503+
publish_log(
504+
log_events_id,
505+
{
506+
"tool_id": tool_id,
507+
"prompt_key": prompt_name,
508+
"doc_name": doc_name,
509+
},
510+
LogLevel.INFO,
511+
RunLevel.RUN,
512+
"Unable to parse JSON response from LLM, try using our"
513+
" cloud / enterprise feature of 'line-item', "
514+
"'record' or 'table' type",
503515
)
504516
structured_output[output[PSKeys.NAME]] = {}
505517

@@ -512,7 +524,6 @@ def prompt_processor() -> Any:
512524
output[PSKeys.NAME]
513525
].rstrip("\n")
514526

515-
enable_challenge = tool_settings.get(PSKeys.ENABLE_CHALLENGE)
516527
# Challenge condition
517528
if enable_challenge:
518529
challenge_plugin: dict[str, Any] = plugins.get(PSKeys.CHALLENGE, {})

unstract/core/src/unstract/core/utilities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def build_tool_container_name(
4141
if len(container_name) > 63:
4242
logger.warning(
4343
f"Container name exceeds 63 char limit for '{container_name}', "
44-
"truncating to 63 chars. There might be collisions in container names"
44+
"truncating to 63 chars. There might be collisions in container names."
45+
f"Truncated container name: {container_name[:63]}"
4546
)
4647
return container_name[:63]

0 commit comments

Comments
 (0)