Modules
Agent Modules¶
create_agent¶
Create and return a configured Agent.
Initializes a strands Agent with the provided BedrockModel, system prompt, and tools.
Parameters: - model: BedrockModel powering the Agent. - system_prompt: Instructional prompt guiding the Agent. - tools: Optional list of tool names, specs, or tool objects to register.
Returns: - Agent: The initialized Agent instance.
Raises: - ValueError: If model or system_prompt is not provided.
Example:
agent = create_agent(
model=bedrock_model,
system_prompt=SYSTEM_PROMPT,
)
Source code in src/doc_redaction/agent.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
Agentic Workflow Modules¶
run_doc_processing_wf¶
Source code in src/doc_redaction/workflow.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
Output Modules¶
SensitiveData¶
Bases: BaseModel
Represents sensitive data detected in a document.
Source code in src/doc_redaction/output.py
68 69 70 71 72 73 74 75 76 |
|
Tool Modules¶
detect_sensitive_data¶
Tool for detecting sensitive data in markdown documents.
detect_sensitive_data(markdown_content)
¶
Detects and extracts sensitive information from markdown documents.
Source code in src/doc_redaction/tool/detect_sensitive_data.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
remove_markdown_formatting(markdown_text)
¶
Remove markdown formatting for cleaner analysis.
Source code in src/doc_redaction/tool/detect_sensitive_data.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
redact_sensitive_data¶
Tool for redacting sensitive information from markdown documents.
apply_redactions(content, rules, redaction_symbol, preserve_structure)
¶
Apply redaction rules to the content based on user specifications.
Source code in src/doc_redaction/tool/redact_sensitive_data.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
extract_custom_terms(rules)
¶
Extract potential custom terms to redact from the rules text. This is a simple approach - could be enhanced with NLP.
Source code in src/doc_redaction/tool/redact_sensitive_data.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
redact_pattern(content, pattern, redaction_symbol, preserve_structure, case_insensitive=False)
¶
Redact matches of a specific pattern in the content.
Source code in src/doc_redaction/tool/redact_sensitive_data.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
redact_sensitive_data(tool, **kwargs)
¶
Redact sensitive information from markdown documents based on user specifications.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool
|
ToolUse
|
The tool use object containing tool execution details |
required |
**kwargs
|
Any
|
Additional arguments passed to the tool |
{}
|
Returns:
Name | Type | Description |
---|---|---|
ToolResult |
ToolResult
|
The redacted markdown document |
Source code in src/doc_redaction/tool/redact_sensitive_data.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
Data Storage¶
Write a JSON-formatted string to a file and log the operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str
|
JSON string content to write. |
required |
filename
|
str
|
Destination file path. Existing content will be overwritten. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
OSError
|
If the file cannot be opened or written. |
Logs
INFO: On successful save with the target file path.
Example
save_as_json(res, "data/confidential/rocketbase_aws_agreement_sensitive_structures_v4.json")
Source code in src/doc_redaction/tool/store_data.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Other Tools¶
Parse a JSON object string and return only the items with non-empty values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
A JSON-encoded object mapping string keys to lists of strings. |
required |
Returns:
Type | Description |
---|---|
dict[str, list[str]]
|
A dict[str, list[str]] containing only entries whose values are truthy (e.g., non-empty lists). |
Raises:
Type | Description |
---|---|
JSONDecodeError
|
If the input is not valid JSON. |
Source code in src/doc_redaction/tool/tool_utils.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Utility Modules¶
This section includes common utility functions.¶
save_as_json¶
Write a JSON-formatted string to a file and log the operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
str
|
JSON string content to write. |
required |
filename
|
str
|
Destination file path. Existing content will be overwritten. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
OSError
|
If the file cannot be opened or written. |
Logs
INFO: On successful save with the target file path.
Example
save_as_json(res, "data/confidential/rocketbase_aws_agreement_sensitive_structures.json")
Source code in src/doc_redaction/utils.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
get_pdf_page_count¶
Return the number of pages in a PDF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the local PDF file. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Total number of pages in the PDF. |
Raises:
Type | Description |
---|---|
PDFProcessingError
|
If the file cannot be opened, is not a valid PDF, or the page count cannot be determined. |
Example
page_count = get_pdf_page_count("path/to/file.pdf") print(f"The document has {page_count} pages.")
Source code in src/doc_redaction/utils.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
get_file_size¶
Return the size of a file in bytes.
Parameters:
file_path (str): Path to the file.
Returns:
int: File size in bytes.
Raises:
FileNotFoundError: If the file does not exist.
OSError: If the size cannot be retrieved due to an OS-related error.
Example:
size = get_file_size("/path/to/file.txt")
print(f"File size: {size} bytes")
Source code in src/doc_redaction/utils.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
InvalidDocumentKeyError¶
Bases: ValueError
Raised when the provided document key is missing or invalid.
Source code in src/doc_redaction/utils.py
14 15 16 17 18 |
|
MissingArgumentError¶
Bases: ValueError
Raised when a required argument is missing.
Source code in src/doc_redaction/utils.py
7 8 9 10 11 |
|
PDFProcessingError¶
Bases: Exception
Raised when PDF processing fails.
Source code in src/doc_redaction/utils.py
21 22 23 24 25 26 |
|