1+ """
2+ llm_processing.py
3+ -----------------
4+ Handles claim extraction and fact verification tasks using the Groq LLM API.
5+
6+ This module:
7+ - Connects to the Groq API with credentials from environment variables.
8+ - Extracts verifiable factual claims from text.
9+ - Verifies claims using provided search results and evidence.
10+ - Returns structured responses with verdicts and explanations.
11+
12+ Functions:
13+ run_claim_extractor_sdk(state: dict) -> dict:
14+ Extracts up to three concise, verifiable claims from the input text
15+ stored in the `state` dictionary.
16+
17+ run_fact_verifier_sdk(search_results: list[dict]) -> dict:
18+ Evaluates provided claims against web search evidence and returns
19+ structured JSON verdicts for each claim.
20+
21+ Environment Variables:
22+ GROQ_API_KEY (str): API key for authenticating with Groq.
23+ """
24+
25+
126import os
227from groq import Groq
328from dotenv import load_dotenv
429import json
530import re
31+ from app .logging .logging_config import setup_logger
32+
33+ logger = setup_logger (__name__ )
634
735load_dotenv ()
836
@@ -41,6 +69,8 @@ def run_claim_extractor_sdk(state):
4169 )
4270
4371 extracted_claims = chat_completion .choices [0 ].message .content .strip ()
72+ logger .debug (f"Extracted claims:\n { extracted_claims } " )
73+
4474
4575 return {
4676 ** state ,
@@ -49,7 +79,7 @@ def run_claim_extractor_sdk(state):
4979 }
5080
5181 except Exception as e :
52- print ( f "Error in claim_extraction: { e } " )
82+ logger . exception ( "Error in claim_extraction" )
5383 return {
5484 "status" : "error" ,
5585 "error_from" : "claim_extraction" ,
@@ -107,13 +137,13 @@ def run_fact_verifier_sdk(search_results):
107137
108138 # Strip markdown code blocks if present
109139 content = re .sub (r"^```json|```$" , "" , content ).strip ()
110- print ( content )
140+ logger . debug ( f"Raw LLM fact verification output: \n { content } " )
111141
112142 # Try parsing the JSON response
113143 try :
114144 parsed = json .loads (content )
115145 except Exception as parse_err :
116- print (f"❌ LLM JSON parse error: { parse_err } " )
146+ logger . error (f"LLM JSON parse error: { parse_err } " )
117147
118148 results_list .append (parsed )
119149
@@ -124,7 +154,7 @@ def run_fact_verifier_sdk(search_results):
124154 }
125155
126156 except Exception as e :
127- print ( f"🔥 Error in fact_verification: { e } " )
157+ logger . exception ( " Error in fact_verification" )
128158 return {
129159 "status" : "error" ,
130160 "error_from" : "fact_verification" ,
0 commit comments