Skip to content

Per-provider attachment validation: registry overrides + inline file-MIME gating#130

Draft
adambalogh wants to merge 2 commits into
mainfrom
claude/deepseek-v4-pdf-error-39cqqs
Draft

Per-provider attachment validation: registry overrides + inline file-MIME gating#130
adambalogh wants to merge 2 commits into
mainfrom
claude/deepseek-v4-pdf-error-39cqqs

Conversation

@adambalogh

@adambalogh adambalogh commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Attaching a PDF to deepseek-v4-pro forwarded the file to ByteDance ModelArk, which rejected it with a raw 400 (Model do not support image input). The attachment gate fails open for models without LangChain profile data — which is every model routed through the generic OpenAI-compatible client (ByteDance, Nous, Z.ai) — and even for profiled models it only gated modalities (image/PDF), not which file types a provider's chat endpoint actually accepts inline.

Changes

Registry capability overrides (model_registry.py): optional image_inputs / pdf_inputs on ModelConfig (None = defer to the LangChain profile, as before). Overlaid on the profile in get_model_capabilities. Set to False on the models confirmed text-only by their providers' docs:

  • DeepSeek V4 Flash/Pro (absent from ModelArk's visual-understanding model list)
  • Hermes 4 405B/70B (Llama-3.1 text base)
  • GLM-5.2 (Z.ai restricts multimodal content parts to its V-series vision models)

Seed models (1.6/1.8/2.0-lite) intentionally keep failing open for images — ModelArk documents image input on the Chat API for them.

Per-provider file-MIME allowlists (llm_backend.py): validate_attachments now also checks each inline file part's MIME type against what the provider's chat endpoint documents (July 2026):

  • Anthropic: application/pdf only (base64 document blocks don't take Office/text formats — Anthropic's docs require converting those to text or PDF first)
  • Google: PDF + text-family types (text/plain, text/csv, text/markdown, …) which Gemini text-extracts
  • OpenAI: unrestricted — its file-inputs expansion accepts PDFs plus a broad set of Office/CSV/text/code formats, so the provider validates specifics
  • xAI / ByteDance / Nous / Z.ai: no inline file input on the chat path at all (their document features are separate Responses-API or URL/file-id workflows), so any file part gets a clean 400 here

All rejections raise AttachmentValidationError → the existing clean 400 ("Model 'grok-4.5' does not support application/pdf file attachments.") instead of a provider's raw error.

Tests

New: provider MIME allowlist (docx→GPT passes, docx→Claude/Gemini rejected, csv→Gemini passes, PDF→Grok/Seed rejected), text-only overrides for DeepSeek/Hermes/GLM (both modalities), override-beats-profile, Seed image fail-open. Full suite: 195 passed, 3 skipped; make lint clean.

Notes

Companion chat-app PR (OpenGradient/chat-app#649) drives the same matrix in the UI (per-model accept lists, mismatch gating, and client-side text-file folding — text files reach the gateway as plain message text, not file parts).

🤖 Generated with Claude Code

https://claude.ai/code/session_011rvJNkR8AK28peRgs4bVRu

claude added 2 commits July 13, 2026 13:09
Attaching a PDF (or image) to deepseek-v4-pro/-flash was forwarded to
ByteDance ModelArk and came back as a raw 400 ("Model do not support
image input"). The attachment gate in validate_attachments fails open
for models without LangChain profile data, which covers every ModelArk
model routed through the generic OpenAI-compatible client.

Add per-model attachment capability overrides (image_inputs /
pdf_inputs) to ModelConfig, overlay them on the LangChain profile in
get_model_capabilities, and mark the text-only DeepSeek V4 models as
supporting neither — so the gateway now rejects these requests up front
with its clean "does not support document/image attachments" 400.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011rvJNkR8AK28peRgs4bVRu
Extends attachment validation beyond the boolean image/PDF modality gates
to what each provider's chat endpoint actually accepts inline (per
provider docs, July 2026):

- Per-provider file-part MIME allowlists in validate_attachments:
  Anthropic and Gemini accept PDFs (Gemini also text-family types);
  OpenAI is unrestricted (its file-inputs cover Office/CSV/text/code
  formats); xAI, ByteDance, Nous and Z.ai have no inline file input on
  the chat path, so file parts get a clean 400 instead of the provider's
  raw error.
- Registry capability overrides for the remaining text-only models:
  Hermes 4 405B/70B (Llama-3.1 text base) and GLM-5.2 (Z.ai restricts
  multimodal parts to its V-series models) now reject image and document
  attachments up front, like DeepSeek V4.
- Seed models keep failing open for images: ModelArk documents image
  input on the chat API for seed-1.6/1.8/2.0-lite.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011rvJNkR8AK28peRgs4bVRu
@adambalogh adambalogh changed the title Reject unsupported attachments for DeepSeek V4 with a clean error Per-provider attachment validation: registry overrides + inline file-MIME gating Jul 13, 2026
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.

2 participants