Skip to content

📄 feat: Model-Aware Bedrock Document Size Validation#12467

Merged
danny-avila merged 4 commits into
devfrom
claude/stupefied-dubinsky
Mar 30, 2026
Merged

📄 feat: Model-Aware Bedrock Document Size Validation#12467
danny-avila merged 4 commits into
devfrom
claude/stupefied-dubinsky

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Summary

I removed the hard 4.5 MB clamp on Bedrock document uploads so that model-specific exceptions documented by AWS are respected. Previously, Bedrock was the only provider where fileConfig could not raise the size limit above the default — this change makes Bedrock consistent with every other provider.

  • Add model parameter threading from BaseClient.addDocuments() through encodeAndFormatDocuments to validateBedrockDocument
  • Introduce isBedrockClaude4Plus() and isBedrockNova() matchers to detect exempt model IDs
  • Exempt Claude 4+ PDFs and Nova PDF/DOCX from the 4.5 MB default, using 32 MB (Bedrock max request payload) as the fallback limit
  • Replace Math.min(configuredFileSizeLimit, providerLimit) with configuredFileSizeLimit ?? providerLimit so fileConfig can override in either direction, matching Anthropic/OpenAI/Google behavior
  • Preserve the 4.5 MB default for non-exempt Bedrock models and document types
  • Update validation and document encoding tests to cover model-specific exemptions and the new override behavior

Ref: AWS Bedrock inference API restrictions — Claude 4+ PDFs and Nova PDF/DOCX are exceptions to the 4.5 MB per-document limit.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

Ran the full validation and document encoding test suites (84 tests passing):

npx jest src/files/validation.spec.ts src/files/encode/document.spec.ts --no-coverage

Key test scenarios added:

  • Claude 4+ model (anthropic.claude-sonnet-4-20250514-v1:0) accepts PDFs >4.5 MB up to 32 MB
  • Nova model (amazon.nova-pro-v1:0) accepts PDFs and DOCX >4.5 MB
  • Claude 4+ DOCX is not exempt (only PDF per AWS docs)
  • Non-exempt models (e.g. Claude 3.5) still enforce the 4.5 MB default
  • fileConfig can now raise or lower Bedrock limits (previously could only lower)

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Remove the hard 4.5MB clamp on Bedrock document uploads so that
Claude 4+ (PDF) and Nova (PDF/DOCX) models can accept larger files
per AWS documentation. The default 4.5MB limit is preserved for
other models/formats, and fileConfig can now override it in either
direction—consistent with every other provider.
Copilot AI review requested due to automatic review settings March 30, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Bedrock document/PDF validation to be model-aware (respecting AWS-documented exceptions to the 4.5MB default) and threads the selected model through the document encoding pipeline so validation can apply the correct limits.

Changes:

  • Thread model from BaseClientencodeAndFormatDocuments()validatePdf()/validateBedrockDocument().
  • Add Bedrock model/type exemption logic (Claude 4+ PDFs, Nova PDF/DOCX) with a 32MB fallback limit and update validation/encoding tests.
  • Large set of locale JSON updates (additions/removals/rewrites).

Reviewed changes

Copilot reviewed 37 out of 39 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
packages/api/src/files/validation.ts Adds model-aware Bedrock document limit exemptions and threads optional model into validatePdf/validateBedrockDocument.
packages/api/src/files/validation.spec.ts Adds/updates tests for Bedrock model-specific exemptions and config override behavior.
packages/api/src/files/encode/document.ts Threads model into validation calls during document encoding/formatting.
packages/api/src/files/encode/document.spec.ts Updates mocks/assertions for the new optional model parameter.
api/app/clients/BaseClient.js Passes selected model into document encoding/validation pipeline.
client/src/locales/zh-Hant/translation.json Removes several translation keys.
client/src/locales/vi/translation.json Adds/updates many translation keys.
client/src/locales/uk/translation.json Removes several translation keys.
client/src/locales/tr/translation.json Removes several translation keys.
client/src/locales/th/translation.json Removes some keys and adds zoom-related keys.
client/src/locales/sv/translation.json Adds/updates agents-related keys and removes some keys.
client/src/locales/sl/translation.json Removes some keys.
client/src/locales/ru/translation.json Adds/updates many keys; includes several incomplete/broken strings.
client/src/locales/pt-PT/translation.json Adds/updates many keys; includes placeholder text for chat direction.
client/src/locales/pt-BR/translation.json Adds/updates a few keys and removes some keys.
client/src/locales/nl/translation.json Adds/updates many keys and removes some keys.
client/src/locales/nb/translation.json Removes several translation keys.
client/src/locales/lv/translation.json Adds/updates many keys and removes some keys.
client/src/locales/ko/translation.json Removes several translation keys.
client/src/locales/ka/translation.json Removes several translation keys.
client/src/locales/id/translation.json Removes one translation key.
client/src/locales/hy/translation.json Removes one translation key.
client/src/locales/hu/translation.json Removes several translation keys.
client/src/locales/he/translation.json Removes several translation keys and adds language list entries.
client/src/locales/fr/translation.json Adds/updates many keys and removes some keys.
client/src/locales/fi/translation.json Removes several translation keys.
client/src/locales/et/translation.json Removes several translation keys.
client/src/locales/es/translation.json Rewrites/adds many keys; includes several Spanish translation issues (including reversed zoom strings).
client/src/locales/en/translation.json Reorders/adds keys and fixes placements; also used to anchor PR-description discrepancy comment.
client/src/locales/de/translation.json Removes several translation keys.
client/src/locales/da/translation.json Removes several translation keys.
client/src/locales/cs/translation.json Updates some keys and removes several translation keys.
client/src/locales/ca/translation.json Removes several translation keys.
client/src/locales/ar/translation.json Adds agents-related keys; includes an incorrect agent card label string (missing placeholders).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"com_ui_enter_api_key": "Введите API-ключ",
"com_ui_enter_description": "Введите описание (опционально)",
"com_ui_enter_key": "Вставьте ключ",
"com_ui_enter_name": "Вве",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_ui_enter_name is truncated ("Вве"), which will render an incomplete prompt in the UI. Please replace it with the full Russian translation.

Suggested change
"com_ui_enter_name": "Вве",
"com_ui_enter_name": "Введите имя",

Copilot uses AI. Check for mistakes.
"com_ui_on": "Вкл.",
"com_ui_open_var": "Открыть {{0}}",
"com_ui_openai": "OpenAI",
"com_ui_opens_new_tab": "(",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_ui_opens_new_tab is set to just "(" which looks like a broken/incomplete translation and will likely display incorrectly. It should be a complete string (typically something like "(opens in a new tab)").

Suggested change
"com_ui_opens_new_tab": "(",
"com_ui_opens_new_tab": "(откроется в новой вкладке)",

Copilot uses AI. Check for mistakes.
Comment on lines +812 to +814
"com_ui_zoom_in": "Menos Zoom",
"com_ui_zoom_level": "Nivelar Zoom",
"com_ui_zoom_out": "Mas Zoom",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spanish zoom labels appear reversed: com_ui_zoom_in is "Menos Zoom" (zoom out) and com_ui_zoom_out is "Mas Zoom" (zoom in). This will confuse users; please swap/correct these strings (and add the accent: "Más").

Suggested change
"com_ui_zoom_in": "Menos Zoom",
"com_ui_zoom_level": "Nivelar Zoom",
"com_ui_zoom_out": "Mas Zoom",
"com_ui_zoom_in": "Más Zoom",
"com_ui_zoom_level": "Nivelar Zoom",
"com_ui_zoom_out": "Menos Zoom",

Copilot uses AI. Check for mistakes.
"com_agents_category_rd_description": "Agentes centrados en procesos de I+D, innovación e investigación técnica",
"com_agents_category_sales": "Ventas",
"com_agents_category_sales_description": "Agentes enfocados en procesos de venta, relaciones con el cliente",
"com_agents_category_sales_description": "Agentes enfocados en procesos de venta, relaciones con el client",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_agents_category_sales_description ends with "client" (missing the final "e"), which reads like a truncated word in Spanish.

Suggested change
"com_agents_category_sales_description": "Agentes enfocados en procesos de venta, relaciones con el client",
"com_agents_category_sales_description": "Agentes enfocados en procesos de venta, relaciones con el cliente",

Copilot uses AI. Check for mistakes.
"com_agents_error_generic": "Hemos encontrado un problema al cargar el contenido.",
"com_agents_error_invalid_request": "Petición inválida",
"com_agents_error_loading": "Error al cargar los agentes",
"com_agents_error_loading": "Error al cargar los agente",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_agents_error_loading uses "los agente" (singular) which is grammatically incorrect in Spanish; it should be plural ("los agentes").

Suggested change
"com_agents_error_loading": "Error al cargar los agente",
"com_agents_error_loading": "Error al cargar los agentes",

Copilot uses AI. Check for mistakes.
"com_ui_date_previous_30_days": "За последние 30 дней",
"com_ui_date_previous_7_days": "Предыдущие 7 дней",
"com_ui_date_september": "Сентябрь",
"com_ui_date_sort": "Сорти",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_ui_date_sort is truncated ("Сорти"). This will render as an incomplete label in the UI; please replace it with the full translation (e.g. "Сортировать").

Suggested change
"com_ui_date_sort": "Сорти",
"com_ui_date_sort": "Сортировать",

Copilot uses AI. Check for mistakes.
Comment on lines 1 to 12
{
"chat_direction_left_to_right": "Left to Right",
"chat_direction_right_to_left": "Right to Left",
"com_a11y_ai_composing": "The AI is still composing.",
"com_a11y_chats_date_section": "Chats from {{date}}",
"com_a11y_end": "The AI has finished their reply.",
"com_a11y_selected": "selected",
"com_a11y_start": "The AI has started their reply.",
"com_a11y_summarize_completed": "Context summarized.",
"com_a11y_summarize_failed": "Summarization failed, continuing with available context.",
"com_a11y_summarize_started": "Summarizing context.",
"com_a11y_start": "The AI has started their reply.",
"com_agents_agent_card_label": "{{name}} agent. {{description}}",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR includes large-scale locale/translation changes (many client/src/locales/*/translation.json edits) that aren’t mentioned in the PR description, which makes review/risk assessment harder. Please clarify why these translation updates are included here or split them into a separate PR.

Copilot uses AI. Check for mistakes.
@@ -1,20 +1,35 @@
{
"chat_direction_left_to_right": "algo precisa de ser feito aqui. estava vazio",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chat_direction_left_to_right is still a placeholder string ("algo precisa de ser feito aqui. estava vazio"). This should be replaced with an actual pt-PT translation (consistent with other locales, e.g. "Esquerda para a direita").

Suggested change
"chat_direction_left_to_right": "algo precisa de ser feito aqui. estava vazio",
"chat_direction_left_to_right": "Esquerda para a direita",

Copilot uses AI. Check for mistakes.
"com_a11y_ai_composing": "الذكاء الاصطناعي ما زال يكتب",
"com_a11y_end": "انتهى الذكاء الاصطناعي من الرد",
"com_a11y_start": "بدأ الذكاء الاصطناعي بالرد",
"com_agents_agent_card_label": "البوسنية",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_agents_agent_card_label value appears incorrect and drops the {{name}}/{{description}} placeholders used by the UI. Without those placeholders the agent card label won’t include the agent name/description.

Suggested change
"com_agents_agent_card_label": "البوسنية",
"com_agents_agent_card_label": "{{name}}: {{description}}",

Copilot uses AI. Check for mistakes.
"com_ui_delete_action_confirm": "Вы действительно хотите удалить это действие?",
"com_ui_delete_agent": "Удалить агента",
"com_ui_delete_agent_confirm": "Вы действительно хотите удалить этого агента?",
"com_ui_delete_assistant": "Уд",

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This label is truncated ("Уд"), which will show an incomplete UI string for the delete-assistant action. Please replace it with the full Russian translation (e.g. the equivalent of "Delete assistant").

Suggested change
"com_ui_delete_assistant": "Уд",
"com_ui_delete_assistant": "Удалить ассистента",

Copilot uses AI. Check for mistakes.
@danny-avila
danny-avila changed the base branch from main to dev March 30, 2026 16:20
…, add tests

- Restore Math.min clamp for non-exempt Bedrock documents (fileConfig can
  only lower the hard 4.5 MB API limit, not raise it); only exempt models
  (Claude 4+ PDF, Nova PDF/DOCX) use ?? to allow fileConfig override
- Replace copied isBedrockClaude4Plus regex with cleaner anchored pattern
  that correctly handles multi-digit version numbers (e.g. sonnet-40)
  and removes dead Alt 1 branch matching no real Bedrock model IDs
- Tighten isBedrockNova from includes() to startsWith() to prevent
  substring matching in unexpected positions
- Add integration test verifying model is threaded to validateBedrockDocument
- Add boundary tests for exempt + low configuredFileSizeLimit, non-exempt
  + high configuredFileSizeLimit, and exempt model accepting files up to 32 MB
- Revert two tests that were incorrectly inverted to prove wrong behavior
- Fix inaccurate JSDoc and misleading test name
Make Bedrock consistent with all other providers — fileConfig sets the
effective limit unconditionally via ?? rather than clamping with Math.min.
The model-aware defaults (4.5 MB for non-exempt, 32 MB for exempt) remain
as sensible fallbacks when no fileConfig is set.
@danny-avila danny-avila changed the title 📄 fix: Model-Aware Bedrock Document Size Validation 📄 feat: Model-Aware Bedrock Document Size Validation Mar 30, 2026
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c518dbeddd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/files/validation.ts Outdated
Bedrock cross-region inference profiles prepend a region code to the
model ID (e.g. "us.amazon.nova-pro-v1:0", "eu.anthropic.claude-sonnet-4-...").
Both isBedrockNova and isBedrockClaude4Plus would miss these prefixed IDs,
silently falling back to the 4.5 MB default for eligible models.

Switch both matchers to use (?:^|\.) to anchor the vendor segment so the
pattern matches with or without a leading region prefix.
@danny-avila
danny-avila merged commit 1455f15 into dev Mar 30, 2026
10 checks passed
@danny-avila
danny-avila deleted the claude/stupefied-dubinsky branch March 30, 2026 20:50
yidianyiko pushed a commit to yidianyiko/LibreChat that referenced this pull request Apr 13, 2026
* 📄 fix: Model-Aware Bedrock Document Size Validation

Remove the hard 4.5MB clamp on Bedrock document uploads so that
Claude 4+ (PDF) and Nova (PDF/DOCX) models can accept larger files
per AWS documentation. The default 4.5MB limit is preserved for
other models/formats, and fileConfig can now override it in either
direction—consistent with every other provider.

* address review: restore Math.min for non-exempt docs, tighten regexes, add tests

- Restore Math.min clamp for non-exempt Bedrock documents (fileConfig can
  only lower the hard 4.5 MB API limit, not raise it); only exempt models
  (Claude 4+ PDF, Nova PDF/DOCX) use ?? to allow fileConfig override
- Replace copied isBedrockClaude4Plus regex with cleaner anchored pattern
  that correctly handles multi-digit version numbers (e.g. sonnet-40)
  and removes dead Alt 1 branch matching no real Bedrock model IDs
- Tighten isBedrockNova from includes() to startsWith() to prevent
  substring matching in unexpected positions
- Add integration test verifying model is threaded to validateBedrockDocument
- Add boundary tests for exempt + low configuredFileSizeLimit, non-exempt
  + high configuredFileSizeLimit, and exempt model accepting files up to 32 MB
- Revert two tests that were incorrectly inverted to prove wrong behavior
- Fix inaccurate JSDoc and misleading test name

* simplify: allow fileConfig to override Bedrock limit in either direction

Make Bedrock consistent with all other providers — fileConfig sets the
effective limit unconditionally via ?? rather than clamping with Math.min.
The model-aware defaults (4.5 MB for non-exempt, 32 MB for exempt) remain
as sensible fallbacks when no fileConfig is set.

* fix: handle cross-region inference profile IDs in Bedrock model matchers

Bedrock cross-region inference profiles prepend a region code to the
model ID (e.g. "us.amazon.nova-pro-v1:0", "eu.anthropic.claude-sonnet-4-...").
Both isBedrockNova and isBedrockClaude4Plus would miss these prefixed IDs,
silently falling back to the 4.5 MB default for eligible models.

Switch both matchers to use (?:^|\.) to anchor the vendor segment so the
pattern matches with or without a leading region prefix.
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
* 📄 fix: Model-Aware Bedrock Document Size Validation

Remove the hard 4.5MB clamp on Bedrock document uploads so that
Claude 4+ (PDF) and Nova (PDF/DOCX) models can accept larger files
per AWS documentation. The default 4.5MB limit is preserved for
other models/formats, and fileConfig can now override it in either
direction—consistent with every other provider.

* address review: restore Math.min for non-exempt docs, tighten regexes, add tests

- Restore Math.min clamp for non-exempt Bedrock documents (fileConfig can
  only lower the hard 4.5 MB API limit, not raise it); only exempt models
  (Claude 4+ PDF, Nova PDF/DOCX) use ?? to allow fileConfig override
- Replace copied isBedrockClaude4Plus regex with cleaner anchored pattern
  that correctly handles multi-digit version numbers (e.g. sonnet-40)
  and removes dead Alt 1 branch matching no real Bedrock model IDs
- Tighten isBedrockNova from includes() to startsWith() to prevent
  substring matching in unexpected positions
- Add integration test verifying model is threaded to validateBedrockDocument
- Add boundary tests for exempt + low configuredFileSizeLimit, non-exempt
  + high configuredFileSizeLimit, and exempt model accepting files up to 32 MB
- Revert two tests that were incorrectly inverted to prove wrong behavior
- Fix inaccurate JSDoc and misleading test name

* simplify: allow fileConfig to override Bedrock limit in either direction

Make Bedrock consistent with all other providers — fileConfig sets the
effective limit unconditionally via ?? rather than clamping with Math.min.
The model-aware defaults (4.5 MB for non-exempt, 32 MB for exempt) remain
as sensible fallbacks when no fileConfig is set.

* fix: handle cross-region inference profile IDs in Bedrock model matchers

Bedrock cross-region inference profiles prepend a region code to the
model ID (e.g. "us.amazon.nova-pro-v1:0", "eu.anthropic.claude-sonnet-4-...").
Both isBedrockNova and isBedrockClaude4Plus would miss these prefixed IDs,
silently falling back to the 4.5 MB default for eligible models.

Switch both matchers to use (?:^|\.) to anchor the vendor segment so the
pattern matches with or without a leading region prefix.
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
* 📄 fix: Model-Aware Bedrock Document Size Validation

Remove the hard 4.5MB clamp on Bedrock document uploads so that
Claude 4+ (PDF) and Nova (PDF/DOCX) models can accept larger files
per AWS documentation. The default 4.5MB limit is preserved for
other models/formats, and fileConfig can now override it in either
direction—consistent with every other provider.

* address review: restore Math.min for non-exempt docs, tighten regexes, add tests

- Restore Math.min clamp for non-exempt Bedrock documents (fileConfig can
  only lower the hard 4.5 MB API limit, not raise it); only exempt models
  (Claude 4+ PDF, Nova PDF/DOCX) use ?? to allow fileConfig override
- Replace copied isBedrockClaude4Plus regex with cleaner anchored pattern
  that correctly handles multi-digit version numbers (e.g. sonnet-40)
  and removes dead Alt 1 branch matching no real Bedrock model IDs
- Tighten isBedrockNova from includes() to startsWith() to prevent
  substring matching in unexpected positions
- Add integration test verifying model is threaded to validateBedrockDocument
- Add boundary tests for exempt + low configuredFileSizeLimit, non-exempt
  + high configuredFileSizeLimit, and exempt model accepting files up to 32 MB
- Revert two tests that were incorrectly inverted to prove wrong behavior
- Fix inaccurate JSDoc and misleading test name

* simplify: allow fileConfig to override Bedrock limit in either direction

Make Bedrock consistent with all other providers — fileConfig sets the
effective limit unconditionally via ?? rather than clamping with Math.min.
The model-aware defaults (4.5 MB for non-exempt, 32 MB for exempt) remain
as sensible fallbacks when no fileConfig is set.

* fix: handle cross-region inference profile IDs in Bedrock model matchers

Bedrock cross-region inference profiles prepend a region code to the
model ID (e.g. "us.amazon.nova-pro-v1:0", "eu.anthropic.claude-sonnet-4-...").
Both isBedrockNova and isBedrockClaude4Plus would miss these prefixed IDs,
silently falling back to the 4.5 MB default for eligible models.

Switch both matchers to use (?:^|\.) to anchor the vendor segment so the
pattern matches with or without a leading region prefix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Allow PDF > 4.5MB when using 'Upload to provider' on bedrock with claude/nova models

2 participants