55from typing import List
66from typing import Optional
77
8+ from datapilot .clients .altimate .utils import get_project_governance_llm_checks
9+ from datapilot .clients .altimate .utils import run_project_governance_llm_checks
10+ from datapilot .core .platforms .dbt .constants import LLM
811from datapilot .core .platforms .dbt .constants import MODEL
912from datapilot .core .platforms .dbt .constants import PROJECT
1013from datapilot .core .platforms .dbt .exceptions import AltimateCLIArgumentError
1114from datapilot .core .platforms .dbt .factory import DBTFactory
1215from datapilot .core .platforms .dbt .insights import INSIGHTS
16+ from datapilot .core .platforms .dbt .insights .schema import DBTInsightResult
17+ from datapilot .core .platforms .dbt .insights .schema import DBTModelInsightResponse
1318from datapilot .core .platforms .dbt .schemas .manifest import Catalog
1419from datapilot .core .platforms .dbt .schemas .manifest import Manifest
1520from datapilot .core .platforms .dbt .utils import get_models
@@ -29,11 +34,19 @@ def __init__(
2934 target : str = "dev" ,
3035 selected_models : Optional [str ] = None ,
3136 selected_model_ids : Optional [List [str ]] = None ,
37+ token : Optional [str ] = None ,
38+ instance_name : Optional [str ] = None ,
39+ backend_url : Optional [str ] = None ,
3240 ):
3341 self .run_results_path = run_results_path
3442 self .target = target
3543 self .env = env
3644 self .config = config or {}
45+ self .token = token
46+ self .instance_name = instance_name
47+ self .backend_url = backend_url
48+ self .manifest = manifest
49+ self .catalog = catalog
3750
3851 self .manifest_wrapper = DBTFactory .get_manifest_wrapper (manifest )
3952 self .manifest_present = True
@@ -86,6 +99,22 @@ def _check_if_skipped(self, insight):
8699 return True
87100 return False
88101
102+ def run_llm_checks (self ):
103+ llm_checks = get_project_governance_llm_checks (self .token , self .instance_name , self .backend_url )
104+ check_names = [check ["name" ] for check in llm_checks if check ["alias" ] not in self .config .get ("disabled_insights" , [])]
105+ if len (check_names ) == 0 :
106+ return {"results" : []}
107+
108+ llm_check_results = run_project_governance_llm_checks (
109+ self .token ,
110+ self .instance_name ,
111+ self .backend_url ,
112+ self .manifest .json () if self .manifest else "" ,
113+ self .catalog .json () if self .catalog else "" ,
114+ check_names ,
115+ )
116+ return llm_check_results
117+
89118 def run (self ):
90119 reports = {
91120 MODEL : {},
@@ -156,4 +185,42 @@ def run(self):
156185 else :
157186 self .logger .info (color_text (f"Skipping insight { insight_class .NAME } as { message } " , YELLOW ))
158187
188+ if self .token and self .instance_name and self .backend_url :
189+ llm_check_results = self .run_llm_checks ()
190+ llm_reports = llm_check_results .get ("results" , [])
191+ llm_insights = {}
192+ for report in llm_reports :
193+ for answer in report ["answer" ]:
194+ location = answer ["unique_id" ]
195+ if location not in llm_insights :
196+ llm_insights [location ] = []
197+ metadata = answer .get ("metadata" , {})
198+ metadata ["source" ] = LLM
199+ metadata ["teammate_check_id" ] = report ["id" ]
200+ metadata ["category" ] = report ["type" ]
201+ llm_insights [location ].append (
202+ DBTModelInsightResponse (
203+ insight = DBTInsightResult (
204+ type = "Custom" ,
205+ name = report ["name" ],
206+ message = answer ["message" ],
207+ reason_to_flag = answer ["reason_to_flag" ],
208+ recommendation = answer ["recommendation" ],
209+ metadata = metadata ,
210+ ),
211+ severity = answer ["severity" ],
212+ path = answer ["path" ] if answer .get ("path" ) else "" ,
213+ original_file_path = answer ["original_file_path" ] if answer .get ("original_file_path" ) else "" ,
214+ package_name = answer ["package_name" ] if answer .get ("package_name" ) else "" ,
215+ unique_id = answer ["unique_id" ],
216+ )
217+ )
218+
219+ if llm_insights :
220+ for key , value in llm_insights .items ():
221+ if key in reports [MODEL ]:
222+ reports [MODEL ][key ].extend (value )
223+ else :
224+ reports [MODEL ][key ] = value
225+
159226 return reports
0 commit comments