When using the chat assistant to search emails on a Microsoft/Outlook account, the request fails with a BadRequest error:
web-1 | [chat]: Building Outlook request {
web-1 | "maxResults": 5,
web-1 | "hasSearchQuery": true,
web-1 | "hasDateFilters": false,
web-1 | "queryWasSanitized": true
web-1 | } {
web-1 | "requestId": "d41c81fa-3b3d-4df7-8a1c-8a2fd5da40d8",
web-1 | "url": "https://837b90b9570e:3000/api/chat",
web-1 | "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "emailAccountId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "email": "xxxxx@xxxxxxx.com",
web-1 | "provider": "microsoft"
web-1 | }
web-1 | [chat]: Using search path {
web-1 | "rawSearchQuery": "from:\"John Doe\"",
web-1 | "effectiveSearchQuery": "from:\"\\\"John Doe\\\"\"",
web-1 | "queryWasSanitized": true
web-1 | } {
web-1 | "requestId": "d41c81fa-3b3d-4df7-8a1c-8a2fd5da40d8",
web-1 | "url": "https://837b90b9570e:3000/api/chat",
web-1 | "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "emailAccountId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "email": "xxxxx@xxxxxxx.com",
web-1 | "provider": "microsoft"
web-1 | }
web-1 | [chat]: Non-retryable error encountered {
web-1 | "error": {
web-1 | "error": "Syntax error: character ':' is not valid at position 4 in 'from:\"\\\"John Doe\\\"\"'.",
web-1 | "attemptNumber": 1,
web-1 | "retriesLeft": 5,
web-1 | "retriesConsumed": 0,
web-1 | "retryDelay": 1000
web-1 | },
web-1 | "code": "BadRequest"
web-1 | } {
web-1 | "requestId": "d41c81fa-3b3d-4df7-8a1c-8a2fd5da40d8",
web-1 | "url": "https://837b90b9570e:3000/api/chat",
web-1 | "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "emailAccountId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "email": "xxxxx@xxxxxxx.com",
web-1 | "provider": "microsoft"
web-1 | }
web-1 | [chat]: Failed to search inbox {
web-1 | "error": {
web-1 | "error": "Syntax error: character ':' is not valid at position 4 in 'from:\"\\\"John Doe\\\"\"'.",
web-1 | "attemptNumber": 1,
web-1 | "retriesLeft": 5,
web-1 | "retriesConsumed": 0,
web-1 | "retryDelay": 1000
web-1 | }
web-1 | } {
web-1 | "requestId": "d41c81fa-3b3d-4df7-8a1c-8a2fd5da40d8",
web-1 | "url": "https://837b90b9570e:3000/api/chat",
web-1 | "userId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "emailAccountId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
web-1 | "email": "xxxxx@xxxxxxx.com"
web-1 | }
Steps to Reproduce
- Connect an Outlook/Microsoft account
- Open the chat assistant
- Ask something like "Show me emails from johndoe@example.com" or "Show me emails from John Doe"
Possible explanation
It seems like the search functionality of Microsoft/Outlook does not support the colon in a query like from:"John Doe" and this is the reason why the BadRequest is returned. In the code of the Microsoft provider, there is even a function stripGmailPrefixes that seems to fix a similar issue for a prefix like subject:, because it is not supported by Microsoft:
// IMPORTANT: This is intentionally lossy!
// Gmail-style prefixes like "subject:" can't be translated to Microsoft Graph because:
// 1. $filter with contains(subject, ...) can't be combined with $search or date filters
// (causes "InefficientFilter" error)
// 2. $search doesn't support field-specific syntax like "subject:term"
//
// We strip the prefixes and use plain $search which searches subject AND body.
// This is broader than intended but still finds relevant messages.
// If subject-specific search is needed in the future, add a dedicated method
// that uses only $filter without $search or date filters.
function stripGmailPrefixes(query: string): string {
return query
.replace(/\b(subject|from|to|label):(?:"[^"]*"|\S+)/gi, (match) => {
// Extract the value without the prefix for searching
const colonIndex = match.indexOf(":");
const value = match.slice(colonIndex + 1);
// Remove quotes if present
return value.replace(/^"|"$/g, "");
})
.replace(/\s+/g, " ")
.trim();
}
However, this function is only called in getMessagesWithPagination, not in searchMessages which also takes a query parameter.
When using the chat assistant to search emails on a Microsoft/Outlook account, the request fails with a
BadRequesterror:Steps to Reproduce
Possible explanation
It seems like the search functionality of Microsoft/Outlook does not support the colon in a
querylikefrom:"John Doe"and this is the reason why theBadRequestis returned. In the code of the Microsoft provider, there is even a functionstripGmailPrefixesthat seems to fix a similar issue for a prefix likesubject:, because it is not supported by Microsoft:However, this function is only called in
getMessagesWithPagination, not insearchMessageswhich also takes aqueryparameter.