mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-19 12:25:13 +02:00
fix: guard against empty query in SPARQL generator (#934)
Split the query once and check the parts list before indexing, preventing an IndexError if the LLM returns an empty or whitespace-only string. Fixes #870.
This commit is contained in:
parent
da7d10e995
commit
76e3358ed3
1 changed files with 5 additions and 2 deletions
|
|
@ -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)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue