Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

Fixed Enforce Type Issues for Boolean and JSON (#262)

Tahier Hussain9b14dae2f9b4
diff --git a/prompt-service/src/unstract/prompt_service/main.py b/prompt-service/src/unstract/prompt_service/main.py
index 130a0b5f8..1d16155a3 100644
--- a/prompt-service/src/unstract/prompt_service/main.py
+++ b/prompt-service/src/unstract/prompt_service/main.py
@@ -464,6 +464,15 @@ def prompt_processor() -> Any:
if assertion_failed or answer.lower() == "na":
structured_output[output[PSKeys.NAME]] = None
else:
+ prompt = f'Extract yes/no from the following text:\n{answer}\n\n\
+ Output in single word.\
+ If the context is trying to convey that the answer is true, \
+ then return "yes", else return "no".'
+ answer, usage = run_completion(
+ llm_helper,
+ llm_li,
+ prompt,
+ )
if answer.lower() == "yes":
structured_output[output[PSKeys.NAME]] = True
else:
@@ -472,6 +481,14 @@ def prompt_processor() -> Any:
if assertion_failed or answer.lower() == "[]" or answer.lower() == "na":
structured_output[output[PSKeys.NAME]] = None
else:
+ prompt = (
+ f"Convert the following text:\n{answer} into valid JSON format."
+ )
+ answer, usage = run_completion(
+ llm_helper,
+ llm_li,
+ prompt,
+ )
# Remove any markdown code blocks
lines = answer.split("\n")
answer = ""