Overview
Query validation offers these benefits:- Immediate feedback: Catch errors without making API calls.
- Reduced API usage: Avoid requests for invalid queries.
- Cost savings: Prevent billable API calls for invalid queries.
- Essential for LLM workflows: Critical when you process thousands of generated queries.
- Consistent behavior: Match server-side validation exactly.
- Better developer experience: Get detailed error messages immediately.
Basic usage
Use thevalidate_query() method to check query syntax before you make API
calls:
Basic query validation
is_valid(bool): Whether the query passes validationerror_message(str): Detailed error description if validation fails, or empty string if valid
Automatic validation in SDK methods
Query validation is enabled by default in methods likeget_all_articles() and
get_all_headlines(). You can control this behavior:
SDK method validation
Validation rules
The SDK validates queries using the same rules as the Newscatcher API.Valid patterns
- Single words
- Multi-word
- Exact phrases
- Boolean operators
- Wildcards
- Grouping
Single words and terms
Invalid patterns
- Forbidden chars
- Invalid wildcards
- Operator errors
- Double operators
- Mixed levels
- Unbalanced
Forbidden characters
Understand automatic AND insertion
The API automatically inserts AND operators between standalone terms, which can create validation conflicts with mixed operator levels. ProblemCommon AND insertion conflicts
Fix AND insertion conflicts
Validate multiple queries
For applications that process multiple queries (like LLM-generated queries), you can validate them in bulk: This approach works well when you work with:- LLM-generated queries that may have syntax issues.
- User input that needs validation before processing.
- Batch processing scenarios where you want to filter valid queries first.
Bulk validation is especially valuable for production applications processing
thousands of queries, as it prevents costly API calls for invalid queries.
Best practices
- Use exact phrases for multi-word terms: When you search for specific phrases, always use double quotes to prevent automatic AND insertion conflicts.
- Validate LLM-generated queries: Essential for applications that process thousands of AI-generated queries to save time and money.
- Group complex queries: Use parentheses to make query logic clear and avoid operator-level conflicts.

