This is my combine_kpi_json function:
def combine_kpi_json(*args):
    combined_output = {
        "kpi_dashboard": []
    }

    for json_obj in args:
        if not json_obj:
            continue

        for role_id, insights_list in json_obj.items():
            role_exists = False

            # Convert KPIInsight objects to JSON using `to_json` method
            serialized_insights_list = [insight.to_json() for insight in insights_list]

            for combined_item in combined_output["kpi_dashboard"]:
                if combined_item["role_id"] == role_id:
                    role_exists = True
                    combined_item["insights"].extend(serialized_insights_list)
                    break

            if not role_exists:
                combined_output["kpi_dashboard"].append({
                    "role_id": role_id,
                    "insights": serialized_insights_list
                })

    # Filter top 2 'kpi' and top 3 'kpi_skill' insights for each role
    for role_data in combined_output["kpi_dashboard"]:
        filtered_insights = []
        
        for insight_data in role_data["insights"]:
            # Extract kpi insights from insight_data
            kpi_insights = insight_data.get("kpi_insights", [])
            
            kpi_list = []
            kpi_skill_list = []
            
            for kpi_insight in kpi_insights:
                insight_details = list(kpi_insight["insights"].values())[0]
                
                # Check the type of insight and categorize them
                if insight_details["insights_type"] == "kpi":
                    kpi_list.append(kpi_insight)
                elif insight_details["insights_type"] == "kpi_skill":
                    kpi_skill_list.append(kpi_insight)

            # Sort by priority (descending) for both 'kpi' and 'kpi_skill'
            sorted_kpi_list = sorted(kpi_list, key=lambda x: list(x["insights"].values())[0]["priority"], reverse=True)
            sorted_kpi_skill_list = sorted(kpi_skill_list, key=lambda x: list(x["insights"].values())[0]["priority"], reverse=True)

            # Take the top 2 from 'kpi' and top 3 from 'kpi_skill'
            top_kpi_list = sorted_kpi_list[:2]
            top_kpi_skill_list = sorted_kpi_skill_list[:3]
            
            # Append the filtered insights to the list
            if top_kpi_list or top_kpi_skill_list:
                filtered_insights.append({
                    "kpi_insights": top_kpi_list + top_kpi_skill_list
                })
        
        # Replace the insights in the role_data with the filtered ones
        role_data["insights"] = filtered_insights

    return combined_output
This is its output:
{
    "kpi_dashboard": [
        {
            "role_id": "zzyz62",
            "insights": [
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Diana Pena-Abel exceeded the average Utilization by 367.26%",
                                    "percent_change": "positive",
                                    "priority": 3.6725593667546264,
                                    "additional_params": {
                                        "kpi_id": 1,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Steady progress! Diana Pena-Abel collected 151236.0$, which is 106645.17$ above the average of 44590.83$.",
                                    "percent_change": "positive",
                                    "priority": 106645.17150395778,
                                    "additional_params": {
                                        "kpi_id": 2,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Diana Pena-Abel exceeded the average Promises Kept by 334.91%",
                                    "percent_change": "positive",
                                    "priority": 3.349076517150394,
                                    "additional_params": {
                                        "kpi_id": 3,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Diana Pena-Abel exceeded the average Promises to Pay by 1807.82%",
                                    "percent_change": "positive",
                                    "priority": 18.07823218997362,
                                    "additional_params": {
                                        "kpi_id": 4,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Steady progress! Diana Pena-Abel collected 800.19$, which is 16.6$ above the average of 783.59$.",
                                    "percent_change": "positive",
                                    "priority": 16.60422163588396,
                                    "additional_params": {
                                        "kpi_id": 5,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Diana Pena-Abel exceeded the average Rolled % by 950.87%",
                                    "percent_change": "positive",
                                    "priority": 9.508681135225377,
                                    "additional_params": {
                                        "kpi_id": 11,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Showing good potential. Diana Pena-Abel's Total Clearance % is currently 328.72% below the average of 6188.72%",
                                    "percent_change": "negative",
                                    "priority": 3.2871650211565537,
                                    "additional_params": {
                                        "kpi_id": 12,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Showing good potential. Diana Pena-Abel's DPA % is currently 420.07% below the average of 7990.07%",
                                    "percent_change": "negative",
                                    "priority": 4.2007393939393864,
                                    "additional_params": {
                                        "kpi_id": 13,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "zzyz62": {
                                    "insights_type": "kpi",
                                    "insights_text": "Showing good potential. Diana Pena-Abel's QC Quality is currently 4.9% below the average of 4.9%",
                                    "percent_change": "negative",
                                    "priority": 0.04895960832313342,
                                    "additional_params": {
                                        "kpi_id": 27,
                                        "agent_id": "zzyz62",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        },
        {
            "role_id": "dz3df2",
            "insights": [
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Maria Vasquez exceeded the average Utilization by 237.26%",
                                    "percent_change": "positive",
                                    "priority": 2.372559366754615,
                                    "additional_params": {
                                        "kpi_id": 1,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Steady progress! Maria Vasquez collected 178198.0$, which is 133607.17$ above the average of 44590.83$.",
                                    "percent_change": "positive",
                                    "priority": 133607.17150395777,
                                    "additional_params": {
                                        "kpi_id": 2,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Maria Vasquez exceeded the average Promises Kept by 244.91%",
                                    "percent_change": "positive",
                                    "priority": 2.449076517150388,
                                    "additional_params": {
                                        "kpi_id": 3,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Maria Vasquez exceeded the average Promises to Pay by 977.82%",
                                    "percent_change": "positive",
                                    "priority": 9.778232189973615,
                                    "additional_params": {
                                        "kpi_id": 4,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Almost there! Maria Vasquez's 5 stands at 778.16$, just -5.43$ below the average of 783.59$.",
                                    "percent_change": "negative",
                                    "priority": 5.425778364116127,
                                    "additional_params": {
                                        "kpi_id": 5,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Maria Vasquez exceeded the average Rolled % by 30.87%",
                                    "percent_change": "positive",
                                    "priority": 0.30868113522537755,
                                    "additional_params": {
                                        "kpi_id": 11,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Showing good potential. Maria Vasquez's Total Clearance % is currently 548.72% below the average of 6188.72%",
                                    "percent_change": "negative",
                                    "priority": 5.487165021156557,
                                    "additional_params": {
                                        "kpi_id": 12,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Great job! Maria Vasquez exceeded the average DPA % by 1013.93%",
                                    "percent_change": "positive",
                                    "priority": 10.139260606060617,
                                    "additional_params": {
                                        "kpi_id": 13,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                },
                {
                    "kpi_insights": [
                        {
                            "role": "agent",
                            "insights": {
                                "dz3df2": {
                                    "insights_type": "kpi",
                                    "insights_text": "Showing good potential. Maria Vasquez's QC Quality is currently 4.9% below the average of 4.9%",
                                    "percent_change": "negative",
                                    "priority": 0.04895960832313342,
                                    "additional_params": {
                                        "kpi_id": 27,
                                        "agent_id": "dz3df2",
                                        "skill_id": null
                                    }
                                }
                            }
                        }
                    ]
                }
            ]
        }
    ]
}
I am not getting filtered list
This is my to_json if it helps
def kpi_insights_to_json(self, delta_value_percent, kpi_id, insight_text, priority_score, emp_id, role_type, insights_type, agent_id, skill_id):
        insights_json = []
        insight_data = {
            "insights_type": insights_type,
            "insights_text": insight_text,
            "percent_change": delta_value_percent,
            "priority": priority_score,
            "additional_params": {
                "kpi_id": kpi_id,
                "agent_id": agent_id,
                "skill_id": skill_id
            }
        }
        insights_json.append({
            "role": role_type,
            "insights": {
                emp_id: insight_data
            }
        })

        return {"kpi_insights": insights_json}