diff --git a/trustgraph-flow/trustgraph/query/ontology/sparql_generator.py b/trustgraph-flow/trustgraph/query/ontology/sparql_generator.py index 44c7e0a1..97fc5f4d 100644 --- a/trustgraph-flow/trustgraph/query/ontology/sparql_generator.py +++ b/trustgraph-flow/trustgraph/query/ontology/sparql_generator.py @@ -202,11 +202,14 @@ ASK {{ if response and isinstance(response, dict): query = response.get('query', '').strip() - if query.upper().startswith(('SELECT', 'ASK', 'CONSTRUCT', 'DESCRIBE')): + parts = query.split() + if parts and parts[0].upper() in ( + 'SELECT', 'ASK', 'CONSTRUCT', 'DESCRIBE', + ): return SPARQLQuery( query=query, variables=self._extract_variables(query), - query_type=query.split()[0].upper(), + query_type=parts[0].upper(), explanation=response.get('explanation', 'Generated by LLM'), complexity_score=self._calculate_complexity(query) )