import re FTS_META_CHARS = r'''["'*()^+-]''' # include ? if you see issues def sanitize_query(q: str, *, allow_ops: bool = False) -> str: q = q.strip() if not q: return q if allow_ops: # escape stray double quotes inside, then wrap q = q.replace('"', '""') return f'"{q}"' # literal search: quote and escape special chars q = re.sub(r'"', '""', q) return f'"{q}"'