import json def extract_json_from_output(output_str: str) -> dict: """ Extracts a JSON object from a string containing extra text. """ start = output_str.find('{') end = output_str.rfind('}') if start == -1 or end == -1: return None json_str = output_str[start:end+1] try: return json.loads(json_str) except json.JSONDecodeError: return None