fix(ontology): guard against empty query string in SPARQL generator#880
Closed
SAY-5 wants to merge 1 commit into
Closed
fix(ontology): guard against empty query string in SPARQL generator#880SAY-5 wants to merge 1 commit into
SAY-5 wants to merge 1 commit into
Conversation
Closes trustgraph-ai#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>
Contributor License Agreement ❌This PR contains commits from author(s) with no linked GitHub account. All commits must be authored by a GitHub user so the CLA can be verified. Please ensure the git author email is associated with a GitHub account, or rewrite the commits with a linked identity. |
Contributor
|
Hey @SAY-5 this tripped over the CLA check. The email used in git commits isn't linked to a Github account. Once that's fixed you'll be prompted to send a message here which would indicate acceptance of the CLA. |
Contributor
|
Other than that, great change, thanks |
Author
|
Thanks @cybermaggedon - I'll fix the commit author email and re-push so the CLA check passes. |
Contributor
|
Closed as not able to complete the CLA currently. Thanks for your interest in the project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #870.
_generate_with_llmintrustgraph-flow/trustgraph/query/ontology/sparql_generator.pydid:If the
startswithguard is ever weakened during refactoring (the issue's primary concern) and the LLM returns an empty / whitespace-onlyquery,query.split()[0]raisesIndexError. The fix computesparts = query.split()once, returnsNoneif empty, and reusesparts[0]for thequery_typeread.Tests
tests/unit/test_query/test_sparql_generator.pyadds three async cases:test_valid_select_response_returns_querySPARQLQuerywithquery_type='SELECT'.test_empty_query_does_not_raise_index_errorqueryfield returnsNoneinstead of crashing.test_whitespace_only_query_does_not_raise_index_errorqueryreturnsNoneafter.strip().The suite uses
pytest.importorskipontrustgraph.query.ontology.sparql_generatorso it skips cleanly in environments where the package's existing import chain cannot resolve.Verification
python -m py_compileon both edited files: clean.pytest tests/unit/test_querylocally: 340 passed, 3 skipped (the new tests, due to a pre-existing relative-import issue inquery_service.pyoutside the deployed FlowProcessor environment).