Search document text
search-document-textSearches a document's text for literal terms or regular expressions and returns each match with surrounding text.
Use this tool when:
Finding a specific clause or term (e.g., notice period, liability cap, governing law).
Checking whether and where a document mentions something.
Prefer this over get-document-text when you only need specific passages. If a snippet is too short, search again with a larger context_chars (up to 2,000); for more than that, call get-document-text with offset as many characters before the match as you need (or 0 if the match is nearer the start) and max_chars about twice that, rather than reading the whole document.
Matching behavior:
Queries are literal text by default (no escaping needed for ".", "(", "$", "[").
Ignores case unless case_sensitive is true (e.g., to tell the defined term "Agreement" from "agreement").
Whitespace in a literal query matches any run of whitespace, including line breaks.
Matches inside longer words ("term" matches "termination" and "determined"); use regex mode with \b for whole words.
Pass several queries in one call for synonyms or translations (e.g., "Kündigung", "termination"); each match names the query it matched.
Returns the earliest matches in document order, up to max_results. If total_matches exceeds the number returned, narrow the query or raise max_results.
Regex mode (regex: true):
Each query is a PCRE regular expression, used as written, without delimiters. Escape special characters to match them literally ($, ., ().
Use it for whole words (\btermination\b), amounts (€\s?[\d.,]+), dates (\d{1,2}.\d{1,2}.\d{4}) and clause references (§\s?\d+).
Write \s+ between words: a space matches only a space, and the text breaks lines within sentences, especially in PDFs.
A pattern must match at least one character. Avoid nested repetition such as (\w+\s?)+, which can take too long and fail.
Handoff & errors:
Offsets are character indices into the same text get-document-text returns. Pass the returned text_hash to get-document-text to make sure the text hasn't changed in between.
If there is no text to search yet (text recognition of a PDF still running, or a new document's text not yet prepared) or none at all (password-protected PDF, unreadable scan), the call fails with a message giving the cause and whether retrying later can help.
The text follows an edit within a few seconds, so right after changing a document it may still show the previous wording.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"document_uuid": "<document_uuid>",
"queries": "<queries>"
},
"name": "search-document-text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| regex | No | Whether each query is a PCRE regular expression rather than literal text. Defaults to false. | |
| queries | Yes | The text to look for, up to 200 characters each: literal text, or regular expressions if regex is true. A match of any of them counts. | |
| max_results | No | Maximum total matches across all queries, returning the earliest ones in document order. Defaults to 20. | |
| context_chars | No | How many characters of text to include on each side of a match in its snippet. Defaults to 300. | |
| document_uuid | Yes | UUID of the document to search. If you don't already have the document's UUID, use the list-documents tool to find it. | |
| case_sensitive | No | Whether upper and lower case must match. Defaults to false. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| matches | No | The matches, in the order they occur in the text. | |
| text_hash | No | Identifies the version of the text that was searched. get-document-text takes it, to read the same version. | |
| total_chars | No | The length of the document's whole text, in characters. | |
| total_matches | No | How many matches the text holds in all. More than the number of matches returned when max_results cut the list short. |