Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

UN-4069 [FIX] Raise upload limit on prompt_output to 10 MB with clear error message (#2331)

harini-venkataraman99dbcff5273b
diff --git a/backend/prompt_studio/prompt_studio_core_v2/internal_views.py b/backend/prompt_studio/prompt_studio_core_v2/internal_views.py
index 7d93e298a..3fcdba182 100644
--- a/backend/prompt_studio/prompt_studio_core_v2/internal_views.py
+++ b/backend/prompt_studio/prompt_studio_core_v2/internal_views.py
@@ -20,6 +20,10 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from rest_framework import status
+# 10 MB — agentic table extraction output with highlight coordinates
+# can exceed Django's default 2.5 MB DATA_UPLOAD_MAX_MEMORY_SIZE.
+_PROMPT_OUTPUT_MAX_BODY = 10 * 1024 * 1024
+
logger = logging.getLogger(__name__)
_ERR_INVALID_JSON = "Invalid JSON"
@@ -126,10 +130,31 @@ def prompt_output(request):
"profile_manager_id": str | null,
"metadata": dict
}
+
+ Uses ``request.read()`` instead of ``request.body`` to bypass
+ Django's ``DATA_UPLOAD_MAX_MEMORY_SIZE`` check. Agentic table
+ extraction output with highlight coordinates can exceed the default
+ 2.5 MB limit; this view enforces its own 10 MB cap instead.
"""
- data, err = _parse_json_body(request)
- if err:
- return err
+ content_length = int(request.META.get("CONTENT_LENGTH") or 0)
+ if content_length > _PROMPT_OUTPUT_MAX_BODY:
+ return JsonResponse(
+ {
+ "success": False,
+ "error": (
+ f"Request body too large ({content_length} bytes, "
+ f"limit {_PROMPT_OUTPUT_MAX_BODY})"
+ ),
+ },
+ status=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
+ )
+ try:
+ data = json.loads(request.read())
+ except json.JSONDecodeError:
+ return JsonResponse(
+ {"success": False, "error": _ERR_INVALID_JSON},
+ status=status.HTTP_400_BAD_REQUEST,
+ )
run_id = data.get("run_id", "")
prompt_ids = data.get("prompt_ids", [])
diff --git a/backend/prompt_studio/prompt_studio_core_v2/tests/test_prompt_output_outputs_validation.py b/backend/prompt_studio/prompt_studio_core_v2/tests/test_prompt_output_outputs_validation.py
index ba81f9785..d2992eb50 100644
--- a/backend/prompt_studio/prompt_studio_core_v2/tests/test_prompt_output_outputs_validation.py
+++ b/backend/prompt_studio/prompt_studio_core_v2/tests/test_prompt_output_outputs_validation.py
@@ -35,7 +35,7 @@ def _request(outputs):
# require_http_methods reads request.method; a MagicMock attribute is not
# the string "POST" and the view short-circuits with 405.
request.method = "POST"
- request.body = json.dumps(
+ body = json.dumps(
{
"run_id": "run-1",
"prompt_ids": [_PROMPT_ID],
@@ -43,7 +43,10 @@ def _request(outputs):
"document_id": _DOC_ID,
"is_single_pass_extract": True,
}
- )
+ ).encode()
+ request.body = body
+ request.read.return_value = body
+ request.META = {"CONTENT_LENGTH": str(len(body))}
return request
@@ -79,14 +82,17 @@ def test_non_mapping_metadata_rejected():
`if not prompts` early exit — so it 500s even with valid outputs."""
request = MagicMock()
request.method = "POST"
- request.body = json.dumps(
+ body = json.dumps(
{
"prompt_ids": [_PROMPT_ID],
"document_id": _DOC_ID,
"outputs": {"invoice_number": "INV-001"},
"metadata": [],
}
- )
+ ).encode()
+ request.body = body
+ request.read.return_value = body
+ request.META = {"CONTENT_LENGTH": str(len(body))}
response = prompt_output(request)
assert response.status_code == 400
assert "metadata must be a JSON object" in _body(response)["error"]
@@ -136,7 +142,10 @@ def test_missing_outputs_defaults_to_empty_dict_and_is_accepted():
"""Absent `outputs` has always meant {}; the guard must not change that."""
request = MagicMock()
request.method = "POST"
- request.body = json.dumps({"prompt_ids": [_PROMPT_ID], "document_id": _DOC_ID})
+ body = json.dumps({"prompt_ids": [_PROMPT_ID], "document_id": _DOC_ID}).encode()
+ request.body = body
+ request.read.return_value = body
+ request.META = {"CONTENT_LENGTH": str(len(body))}
with patch(
"prompt_studio.prompt_studio_v2.models.ToolStudioPrompt.objects"
) as prompts, patch(