Skip to content

Commit

Permalink
fix: Defined enable_challenge in prompt-service for error handling (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
1 parent 019ab7f commit cc56b29
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
25 changes: 18 additions & 7 deletions prompt-service/src/unstract/prompt_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def prompt_processor() -> Any:
if not payload:
raise NoPayloadError
tool_settings = payload.get(PSKeys.TOOL_SETTINGS, {})
enable_challenge = tool_settings.get(PSKeys.ENABLE_CHALLENGE, False)
# TODO: Rename "outputs" to "prompts" in payload
prompts = payload.get(PSKeys.OUTPUTS, [])
tool_id: str = payload.get(PSKeys.TOOL_ID, "")
Expand Down Expand Up @@ -277,7 +278,6 @@ def prompt_processor() -> Any:
metadata=metadata,
execution_source=execution_source,
)
# TODO: Handle metrics for line-item extraction
continue
except APIError as e:
app.logger.error(
Expand Down Expand Up @@ -494,12 +494,24 @@ def prompt_processor() -> Any:
)
structured_output[output[PSKeys.NAME]] = json.loads(answer)
except JSONDecodeError as e:
app.logger.info(
f"JSON format error : {answer}", LogLevel.ERROR
err_msg = (
f"Error parsing response (to json): {e}\n"
f"Candidate JSON: {answer}"
)
app.logger.info(
f"Error parsing response (to json): {e}",
LogLevel.ERROR,
app.logger.info(err_msg, LogLevel.ERROR)
# TODO: Format log message after unifying these types
publish_log(
log_events_id,
{
"tool_id": tool_id,
"prompt_key": prompt_name,
"doc_name": doc_name,
},
LogLevel.INFO,
RunLevel.RUN,
"Unable to parse JSON response from LLM, try using our"
" cloud / enterprise feature of 'line-item', "
"'record' or 'table' type",
)
structured_output[output[PSKeys.NAME]] = {}

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

enable_challenge = tool_settings.get(PSKeys.ENABLE_CHALLENGE)
# Challenge condition
if enable_challenge:
challenge_plugin: dict[str, Any] = plugins.get(PSKeys.CHALLENGE, {})
Expand Down
3 changes: 2 additions & 1 deletion unstract/core/src/unstract/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def build_tool_container_name(
if len(container_name) > 63:
logger.warning(
f"Container name exceeds 63 char limit for '{container_name}', "
"truncating to 63 chars. There might be collisions in container names"
"truncating to 63 chars. There might be collisions in container names."
f"Truncated container name: {container_name[:63]}"
)
return container_name[:63]

0 comments on commit cc56b29

Please sign in to comment.