mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-08 21:02:12 +02:00
fix(ontology): guard against empty query string in SPARQL generator
Closes #870. query.split()[0] in _generate_with_llm raised IndexError when the LLM response 'query' field passed the keyword-startswith guard but split to an empty list (e.g. if the guard is ever weakened during refactoring). Compute parts once, return None when empty, and reuse parts[0] for the query_type read. Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
This commit is contained in:
parent
1ffae12559
commit
0ed5ec00b3
2 changed files with 119 additions and 1 deletions
|
|
@ -203,10 +203,13 @@ ASK {{
|
|||
if response and isinstance(response, dict):
|
||||
query = response.get('query', '').strip()
|
||||
if query.upper().startswith(('SELECT', 'ASK', 'CONSTRUCT', 'DESCRIBE')):
|
||||
parts = query.split()
|
||||
if not parts:
|
||||
return None
|
||||
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