mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-08 12:52:12 +02:00
fix: guard against IndexError on empty query string in SPARQL generator
When query.split() returns an empty list (which can happen if the query is empty or whitespace-only), indexing with [0] raises an IndexError. Extract the split result first and guard against an empty list before accessing the first element. Fixes #870
This commit is contained in:
parent
fe542b3d33
commit
e4d9c53d7b
1 changed files with 3 additions and 1 deletions
|
|
@ -203,10 +203,12 @@ ASK {{
|
|||
if response and isinstance(response, dict):
|
||||
query = response.get('query', '').strip()
|
||||
if query.upper().startswith(('SELECT', 'ASK', 'CONSTRUCT', 'DESCRIBE')):
|
||||
parts = query.split()
|
||||
query_type = parts[0].upper() if parts else 'SELECT'
|
||||
return SPARQLQuery(
|
||||
query=query,
|
||||
variables=self._extract_variables(query),
|
||||
query_type=query.split()[0].upper(),
|
||||
query_type=query_type,
|
||||
explanation=response.get('explanation', 'Generated by LLM'),
|
||||
complexity_score=self._calculate_complexity(query)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue