hermes.validate
Validation
prepare_draft extracts a query and moves solution modifiers out of WHERE. parse_error checks it with rdflib. One repair call is allowed.
Extract
extract_sparql prefers the first fenced block, including a sparql fence, and keeps the first span that starts at SELECT, ASK, CONSTRUCT, or DESCRIBE with any PREFIX lines before it. An empty result raises ValueError.
Lift modifiers
Models often write ORDER BY, LIMIT, GROUP BY, HAVING, or OFFSET inside the outer WHERE block. lift_modifiers moves those lines after the block when they sit at brace depth zero; modifiers inside a nested SELECT stay put.
Parse and repair
parse_error calls rdflib.plugins.sparql.prepareQuery and returns None or the parser message. On an error, the training-free system sends repair_prompt once, then runs extraction and the stages again. A second error raises ValueError. Source: validate.py.