---
schema_version: "1"
id: 00465bd80a0ac1b36204c340a847b1cd72cf54ff7d545399e009a4e2d1e4e8a9
title: Considerations When Writing Custom Chunking Functions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-code-ext/guides/function/considerations-when-writing-custom-function.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-code-ext/guide/considerations-when-writing-custom-function.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 2404ceebc6455b810a7cc91e9217d6c0cf54e338270cd9cfd14ffb008a20c5bb
products:
  - Data 360 Code Extension Guide
  - Data 360 Developer Documentation
---
# Considerations When Writing Custom Chunking Functions

Review guardrails and constraints when writing custom chunking functions for code extension in Data 360.

## Not Supported with Bring Your Own Key (BYOK)

Code extension isn't currently supported in orgs that have BYOK enabled.

## Guardrails for Authoring

Follow these practices while implementing your chunking logic.

### Keep Entrypoint Scripts Maintainable

Keep `payload/entrypoint.py` easy to review and test. Place configuration defaults near the top, move reusable logic into helper functions, and keep the top-level function focused on request validation, chunk assembly, and response creation.

### Add Only Pip-Installable Dependencies

List any Python libraries your function needs in `requirements.txt` (or the equivalent in your payload). Use only pip-installable dependencies. Libraries that require operating system-level installations or system configuration are not supported in the Data 360 execution environment.

### Handle Errors and Edge Cases

Handle missing or malformed input elements gracefully and avoid uncaught exceptions that can fail the entire invocation.

### Keep Chunking Deterministic

For the same input, return stable chunking output so that indexing behavior is predictable across runs. Avoid nondeterministic logic, for example, random ordering or unstable sequence assignment, that can produce different chunk boundaries for identical input.

### Avoid Sensitive Data in Logs

Execution logs may be visible to users with access to the Code Extension logs data lake object (DLO). Do not log personally identifiable information (PII), credentials, or other sensitive data from your chunking logic. Prefer structured logger calls over ad hoc debug prints so that you can control log level and output.

## Runtime Limitations

Be aware of these constraints for custom chunking functions.

### Execution Model

Chunking functions run in a request-response model. They receive a batch of document elements and return a list of chunks. Data 360 can invoke your function multiple times in a single search index run depending on batching. Your function must not read from or write to DLOs or data model objects (DMOs) directly. Use only the request input and return the required output structure. API calls from inside the function aren't supported.

### Package Size and Contents

Keep your deployment package under the size limit, for example, 5 GB. Include only the code and dependencies required for chunking. Unnecessary files increase upload time and can affect startup performance.

### Common Mistakes to Avoid

- Using nondeterministic logic that produces different chunk boundaries for identical input.
- Calling APIs from inside the function.
- Logging sensitive data, such as PII, credentials, or other restricted content.
- Including unnecessary files or oversized dependencies in the deployment package.
- Changing `payload/config.json` unintentionally.
- Relying on mutable global state across invocations instead of processing each request independently.

## See Also

- [Write a Custom Chunking Function](https://developer.salesforce.com/docs/data/data-cloud-code-ext/guide/write-custom-chunking-function.md)
