quickwit-oss/quickwit · error
failed to parse query: `{}`
Error message
failed to parse query: `{}` What it means
parse_user_query converts free-text user input into a query AST using tantivy's query grammar parser. This error is raised when the user_text fails tantivy::query_grammar::parse_query — meaning the query syntax itself is invalid (unbalanced quotes/parens, dangling operators, illegal syntax). The full offending query text is embedded in the message.
Source
Thrown at quickwit/quickwit-query/src/query_ast/user_input_query.rs:66
impl UserInputQuery {
/// Parse the user query to generate a structured QueryAST, without any UserInputQuery node.
///
/// The `UserInputQuery` have an optional search_fields property that takes precedence over
/// the `default_search_fields`.
///
/// In quickwit, the search fields in the `UserInputQuery` are usually supplied with the user
/// request.
/// The default_search_fields argument on the other hand, is the default search fields defined
/// in the `DocMapper`.
pub fn parse_user_query(&self, default_search_fields: &[String]) -> anyhow::Result<QueryAst> {
let search_fields = self
.default_fields
.as_ref()
.map(|search_fields| &search_fields[..])
.unwrap_or(default_search_fields);
let user_input_ast = tantivy::query_grammar::parse_query(&self.user_text)
.map_err(|_| anyhow::anyhow!("failed to parse query: `{}`", &self.user_text))?;
let default_occur = match self.default_operator {
BooleanOperand::And => Occur::Must,
BooleanOperand::Or => Occur::Should,
};
convert_user_input_ast_to_query_ast(
user_input_ast,
default_occur,
search_fields,
self.lenient,
)
}
}
impl From<UserInputQuery> for QueryAst {
fn from(user_text_query: UserInputQuery) -> Self {
QueryAst::UserInput(user_text_query)
}
}View on GitHub (pinned to a39730c5cd)
Solutions
- Fix the query syntax: balance quotes and parentheses, ensure AND/OR/NOT have operands
- Sanitize/escape user input before embedding it in the query string
- Simplify to plain terms to isolate which token breaks parsing
- If building queries programmatically, use the typed QueryAst API instead of string concatenation
Example fix
// before
let q = format!("field:{}", user_input); // user_input = "foo "bar""
// after: escape quotes / use typed AST
let q = format!("field:{}", escape_query_syntax(user_input)); Defensive patterns
Strategy: try-catch
Validate before calling
fn query_parses(q: &str) -> bool { tantivy::query_grammar::parse_query(q).is_ok() } Try / catch
match parse_user_query(&query) {
Err(e) => {
// return 400 to the client with the invalid query text
Err(bad_request(format!("invalid query syntax: {e}")))
}
Ok(ast) => Ok(ast),
} Prevention
- Escape user input containing quotes, parens, and boolean keywords
- Validate query strings client-side with a tantivy-compatible grammar
- Use the structured QueryAst API for programmatic query construction
When it happens
Trigger: Calling UserInputQuery::parse_user_query (via query AST conversion of a user-supplied query string) with text tantivy's grammar rejects: unbalanced quotes, unmatched parentheses, operators like AND/OR/NOT with no operands, or invalid field:value syntax.
Common situations: REST/gRPC clients sending raw user-typed search strings with stray characters; programmatic query builders interpolating values containing quotes or special chars; empty or operator-only query strings.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- The user query should be valid.
- read-only
- Unsupported minimum should match dsl {}. quickwit currently
- fields and default_field cannot be both set in `query_string
- both gt and gte are set
AI-assisted analysis of quickwit-oss/quickwit@a39730c5cd (2026-09-08).
Data as JSON: /api/errors/295a09b61836e45b.
Report an issue: GitHub.