Checks a Box folder hourly and gives each new PDF its own summary document and one row in your index sheet.

UsesClaudeBoxGoogle DocsGoogle Sheets

Summarize and index new documents in a Box folder

Every hour, the Box folder you point it at is listed, the PDFs it has not read before are worked out from your own index sheet, and each new one gets a summary document in Google Docs and one row in that index. Your index sheet is the record of what has already been read.

Each summary document holds a short note saying what the document is, who it involves and any dates or amounts, followed by the exact details read out of it so you can check one against the other. The index row holds the date, the file name, the Box file id, a one-line description and a link to the summary. The note is written from those details alone, and anything not found is left blank, so it cannot assert something the document does not say. Rows are only ever added, only PDFs are read, and one file that cannot be read does not stop the rest.

Before the first run you need an index sheet with five columns: date read, file name, Box file id, what the document is, and a link to the summary.

Run every hour.Run every hour.
Set boxFolderId to blank.Set boxFolderId to blank.
Set indexSpreadsheetUrl to blank.Set indexSpreadsheetUrl to blank.
Set indexSheetTabName to blank.Set indexSheetTabName to blank.
Set maxDocumentsPerRun to 10.Set maxDocumentsPerRun to 10.
Trim boxFolderId and save it as folderId.Trim boxFolderId and save it as folderId.
Trim indexSpreadsheetUrl and save it as spreadsheetUrl.Trim indexSpreadsheetUrl and save it as spreadsheetUrl.
Trim indexSheetTabName and save it as sheetName.Trim indexSheetTabName and save it as sheetName.
Set documentCap to maxDocumentsPerRun multiplied by 1.Set documentCap to maxDocumentsPerRun multiplied by 1.
If documentCap is greater than or equal to 1 is no or documentCap is less than or…If documentCap is greater than or equal to 1 is no or documentCap is less than or…
Yes
Stop and report a problem: The 'maxDocumentsPerRun' step has to be a whole number between 1 and 100. It is how many documents one run will read.Stop and report a problem: The 'maxDocumentsPerRun' step has to be a whole number between 1 and 100. It is how many documents one run will read.
No
No steps
Set alreadySummarised to an empty list.Set alreadySummarised to an empty list.
If a step below fails, save the error as ledgerErrorIf a step below fails, save the error as ledgerError
Try
Google SheetsGoogle SheetsRead column 'C' of sheetName in spreadsheetUrl. Save it as ledger.Read column 'C' of sheetName in spreadsheetUrl. Save it as ledger.
For each ledgerValue in ledger.values:For each ledgerValue in ledger.values:
Trim ledgerValue and save it as seenId. Trim ledgerValue and save it as seenId.
If seenId isn't empty and seenId is not “null” If seenId isn't empty and seenId is not “null”
Yes
Add seenId to the end of alreadySummarised and save it as alreadySummarised.Add seenId to the end of alreadySummarised and save it as alreadySummarised.
No
No steps
On error
Stop and report a problem: Could not read column C of the index sheet, which is the only record of what has already been read - so nothing has been touched. Check the 'indexSpreadsheetUrl' and 'indexSheetTabName' steps. The reason given was: ledgerError.message.Stop and report a problem: Could not read column C of the index sheet, which is the only record of what has already been read - so nothing has been touched. Check the 'indexSpreadsheetUrl' and 'indexSheetTabName' steps. The reason given was: ledgerError.message.
Set folderItems to an empty list.Set folderItems to an empty list.
If a step below fails, save the error as folderErrorIf a step below fails, save the error as folderError
Try
BoxBoxList items in Box folder folderId. Save it as folder.List items in Box folder folderId. Save it as folder.
Change folderItems to folder.items.Change folderItems to folder.items.
On error
Stop and report a problem: Could not list that Box folder, so nothing has been read. Check the id in the 'boxFolderId' step. The reason given was: folderError.message.Stop and report a problem: Could not list that Box folder, so nothing has been read. Check the id in the 'boxFolderId' step. The reason given was: folderError.message.
Set summarisedCount to 0.Set summarisedCount to 0.
Set alreadyDoneCount to 0.Set alreadyDoneCount to 0.
Set notADocumentCount to 0.Set notADocumentCount to 0.
Set failedCount to 0.Set failedCount to 0.
Trim today's date and save it as readOn.Trim today's date and save it as readOn.
For each item in folderItems:For each item in folderItems:
If summarisedCount is greater than or equal to documentCapIf summarisedCount is greater than or equal to documentCap
Yes
Show in the output: Stopped after summarisedCount document(s). The rest of the folder is picked up on the next run.Show in the output: Stopped after summarisedCount document(s). The rest of the folder is picked up on the next run.
Stop repeating.Stop repeating.
No
No steps
Set itemType to blank.Set itemType to blank.
If a step below fails, save the error as itemTypeErrorIf a step below fails, save the error as itemTypeError
Try
Trim item.type and save it as itemType.Trim item.type and save it as itemType.
On error
Change itemType to blank.Change itemType to blank.
If itemType is not “file”If itemType is not “file”
Yes
Skip to the next item.Skip to the next item.
No
No steps
Set fileName to blank.Set fileName to blank.
If a step below fails, save the error as fileNameErrorIf a step below fails, save the error as fileNameError
Try
Trim item.name and save it as fileName.Trim item.name and save it as fileName.
On error
Change fileName to blank.Change fileName to blank.
Trim item.id and save it as fileId.Trim item.id and save it as fileId.
If fileName is empty or fileId is empty or fileId is “null”If fileName is empty or fileId is empty or fileId is “null”
Yes
Show in the output: “Skipped an item in the folder because Box gave it no usable name or id.”.Show in the output: “Skipped an item in the folder because Box gave it no usable name or id.”.
Skip to the next item.Skip to the next item.
No
No steps
If alreadySummarised contains fileIdIf alreadySummarised contains fileId
Yes
Add 1 to alreadyDoneCount.Add 1 to alreadyDoneCount.
Skip to the next item.Skip to the next item.
No
No steps
If fileName doesn't end with “.pdf” (ignoring case)If fileName doesn't end with “.pdf” (ignoring case)
Yes
Add 1 to notADocumentCount.Add 1 to notADocumentCount.
Show in the output: Left alone because it is not a PDF: fileName.Show in the output: Left alone because it is not a PDF: fileName.
Skip to the next item.Skip to the next item.
No
No steps
If a step below fails, save the error as documentErrorIf a step below fails, save the error as documentError
Try
BoxBoxDownload file fileId. Save it as download.Download file fileId. Save it as download.
Trim download.document_ref and save it as documentRef.Trim download.document_ref and save it as documentRef.
Run an AI agent: Read the attached document and pull out each of these fields, in this order: - Document t… and save it as extraction.Run an AI agent: Read the attached document and pull out each of these fields, in this order: - Document t… and save it as extraction.
Set detailLines to an empty list.Set detailLines to an empty list.
Set documentTitle to blank.Set documentTitle to blank.
For each extractedField in extraction.output.fields:For each extractedField in extraction.output.fields:
Set fieldName to blank. Set fieldName to blank.
If a step below fails, save the error as fieldNameError If a step below fails, save the error as fieldNameError
Try
Trim extractedField.name and save it as fieldName.Trim extractedField.name and save it as fieldName.
On error
Change fieldName to blank.Change fieldName to blank.
If fieldName isn't empty If fieldName isn't empty
Yes
Set fieldValue to blank.Set fieldValue to blank.
If a step below fails, save the error as fieldValueErrorIf a step below fails, save the error as fieldValueError
Try
Trim extractedField.value and save it as fieldValue.Trim extractedField.value and save it as fieldValue.
On error
Join extractedField.value with “; ” and save it as fieldValue.Join extractedField.value with “; ” and save it as fieldValue.
If fieldValue isn't emptyIf fieldValue isn't empty
Yes
Add fieldName: fieldValue to the end of detailLines and save it as detailLines.Add fieldName: fieldValue to the end of detailLines and save it as detailLines.
If fieldName is “Document title”If fieldName is “Document title”
Yes
Change documentTitle to fieldValue.Change documentTitle to fieldValue.
No
No steps
No
No steps
No
No steps
Join detailLines with a new line and save it as detailBlock.Join detailLines with a new line and save it as detailBlock.
If detailBlock is emptyIf detailBlock is empty
Yes
Add 1 to failedCount.Add 1 to failedCount.
Show in the output: Nothing could be read out of fileName, so it has been left for you to look at. Nothing was written.Show in the output: Nothing could be read out of fileName, so it has been left for you to look at. Nothing was written.
No
Set summaryText to blank.Set summaryText to blank.
If a step below fails, save the error as summaryErrorIf a step below fails, save the error as summaryError
Try
ClaudeClaudeAsk Claude: 'Below are details read word for word out of one document. Write a short note for someone filing it.Ask Claude: 'Below are details read word for word out of one document. Write a short note for someone filing it. Rules: use only the details below. Do not add anything they do not contain, and do not guess at a detail that came back blank. Do not describe the document as good, bad, urgent or routine - you have not read all of it. Write the first line as one sentence saying what this document is. Then a blank line. Then up to five short lines covering who it involves, what it concerns and any dates or amounts it states. Plain text only. DETAILS READ FROM THE DOCUMENT: detailBlock'. Save it as summaryReply. Maximum response length: 700
Trim summaryReply.response_text and save it as summaryText.Trim summaryReply.response_text and save it as summaryText.
On error
Change summaryText to blank.Change summaryText to blank.
If summaryText is emptyIf summaryText is empty
Yes
Change summaryText to “No written note came back for this document. The details read out of it are below, unchanged.”.Change summaryText to “No written note came back for this document. The details read out of it are below, unchanged.”.
No
No steps
Trim the first item of summaryText split by a new line and save it as headline.Trim the first item of summaryText split by a new line and save it as headline.
Set documentName to documentTitle.Set documentName to documentTitle.
If documentName is emptyIf documentName is empty
Yes
Change documentName to fileName.Change documentName to fileName.
No
No steps
If headline is emptyIf headline is empty
Yes
Change headline to documentName.Change headline to documentName.
No
No steps
Trim the document id from the Google Docs “Create document” step and save it as summaryDocumentId.Trim the document id from the Google Docs “Create document” step and save it as summaryDocumentId.
Google DocsGoogle DocsAdd the heading documentName to summaryDocumentId.Add the heading documentName to summaryDocumentId.
Google DocsGoogle DocsAdd text to summaryDocumentId.Add text to summaryDocumentId.summaryText Read word for word from the document: detailBlock Source file: fileName (Box file fileId), read on readOn.
Google SheetsGoogle SheetsAdd a row to sheetName in spreadsheetUrl.Add a row to sheetName in spreadsheetUrl.
Add 1 to summarisedCount.Add 1 to summarisedCount.
On error
Add 1 to failedCount.Add 1 to failedCount.
Show in the output: Could not read fileName, so it has been left alone and will be tried again next run: documentError.message.Show in the output: Could not read fileName, so it has been left alone and will be tried again next run: documentError.message.
Show in the output: Read and indexed summarisedCount new document(s). Already indexed: alreadyDoneCount. Not a PDF: notADocumentCount. Could not be read: failedCount.Show in the output: Read and indexed summarisedCount new document(s). Already indexed: alreadyDoneCount. Not a PDF: notADocumentCount. Could not be read: failedCount.