abjasrees commited on
Commit
de92f5f
·
verified ·
1 Parent(s): 7a693e5

Update hedis_engine.py

Browse files
Files changed (1) hide show
  1. hedis_engine.py +22 -6
hedis_engine.py CHANGED
@@ -1,5 +1,4 @@
1
  # hedis_engine.py
2
- # interactive_hedis_engine.py
3
  import os
4
  import json
5
  from crewai import Agent, Task, Crew, Process
@@ -89,13 +88,13 @@ class InteractiveHedisComplianceEngine:
89
  hedis_task_description += f"\n\nIncorporate these suggestions: {suggestions}\n"
90
 
91
  hedis_task_description += (
92
- "Return JSON with fields: 'measure','required_tests','required_medications',"
93
- "'codes','timeframes','inclusions','exclusions'."
94
  )
95
 
96
  hedis_task = Task(
97
  description=hedis_task_description,
98
- expected_output="Structured JSON with absolute date ranges.",
99
  agent=self.hedis_expert,
100
  )
101
 
@@ -116,10 +115,27 @@ class InteractiveHedisComplianceEngine:
116
  result = criteria_crew.kickoff(inputs=inputs)
117
 
118
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  # Try to parse as JSON
120
- criteria_json = json.loads(str(result))
121
  return criteria_json
122
- except json.JSONDecodeError:
 
 
123
  # If not valid JSON, return as string
124
  return {"raw_output": str(result)}
125
 
 
1
  # hedis_engine.py
 
2
  import os
3
  import json
4
  from crewai import Agent, Task, Crew, Process
 
88
  hedis_task_description += f"\n\nIncorporate these suggestions: {suggestions}\n"
89
 
90
  hedis_task_description += (
91
+ "IMPORTANT: Return ONLY valid JSON without any markdown formatting, code blocks, or extra text. "
92
+ "The response must start with { and end with } and be valid JSON that can be parsed directly."
93
  )
94
 
95
  hedis_task = Task(
96
  description=hedis_task_description,
97
+ expected_output="Valid JSON object (no markdown, no code blocks) with fields: 'measure','required_tests','required_medications','codes','timeframes','inclusions','exclusions'.",
98
  agent=self.hedis_expert,
99
  )
100
 
 
115
  result = criteria_crew.kickoff(inputs=inputs)
116
 
117
  try:
118
+ # Clean the result string - remove markdown code blocks and extra whitespace
119
+ result_str = str(result).strip()
120
+
121
+ # Remove markdown code blocks if present
122
+ if result_str.startswith("```json"):
123
+ result_str = result_str[7:] # Remove ```json
124
+ elif result_str.startswith("```"):
125
+ result_str = result_str[3:] # Remove ```
126
+
127
+ if result_str.endswith("```"):
128
+ result_str = result_str[:-3] # Remove closing ```
129
+
130
+ # Remove any leading/trailing whitespace and newlines
131
+ result_str = result_str.strip()
132
+
133
  # Try to parse as JSON
134
+ criteria_json = json.loads(result_str)
135
  return criteria_json
136
+ except json.JSONDecodeError as e:
137
+ print(f"JSON parsing error: {e}")
138
+ print(f"Raw result: {repr(str(result))}")
139
  # If not valid JSON, return as string
140
  return {"raw_output": str(result)}
141