Python Code Block
Add custom Python logic to your agent with pre-installed libraries. The Python Code Block lets you process data, integrate with external services, perform calculations, and implement custom business logic within your agent's workflow.
Adding a Python Code Block
Navigate to your agent's workflow editor
- Drag the Python Code Block from the components panel
- Connect it to your desired step in the workflow
- Use the code editor to implement your custom logic
Accessing Parsed File Content
Python code blocks can access the content of files processed by the Intelligent Parser earlier in your agent. This allows you to programmatically manipulate, transform, or extract data from uploaded documents (PDFs, spreadsheets, etc.) directly in Python, without routing them through an LLM step.
Enable Include Parsed Files
The feature is opt-in because file payloads can be large. To enable it:
- Open your Python code block in the Agent Studio.
- Toggle "Include Parsed Files" in the code block toolbar.
The toggle is available in both the classic editor and the vibe experience.
Access Parsed Files in Your Code
When enabled, parsed file content is available in client_data["parsed_files"] as a list of objects. Each entry contains:
| Field | Description | Example |
|---|---|---|
name | Original file name | "report.pdf" |
content | Parsed text output (markdown or structured content) | "# Report\n\nData..." |
file_id | Blob storage identifier | "a1b2c3d4-e5f6-7890-abcd-ef1234567890" |
content_type | MIME type of the original file | "application/pdf" |
for file in client_data.get("parsed_files", []):
print(file["name"]) # e.g. "report.pdf"
print(file["content"]) # Parsed markdown/structured output
print(file["file_id"]) # Blob storage identifier
print(file["content_type"]) # e.g. "application/pdf"Example: Extract and Process Parsed Documents
import json
results = []
for file in client_data.get("parsed_files", []):
if file["content_type"] == "application/pdf":
results.append({
"source": file["name"],
"data": file["content"]
})
output = json.dumps(results)Parsed Files vs. LLM Step Attachments
If your agent also uses LLM steps with the Include Attachments option, here is how the two approaches compare:
| Python Code Block (Include Parsed Files) | LLM Step (Include Attachments) | |
|---|---|---|
| Content delivery | Full content in a single entry per file | Chunked into ~8 KB pieces |
| Processing | Programmatic (your Python code) | Model-driven (prompt-based) |
| Best for | Data extraction, transformation, filtering | Summarization, Q&A, analysis |
Use Include Parsed Files when you need full programmatic control over the document content. Use Include Attachments on an LLM step when you want the model to reason over the content.