Skip to main content
skill CX Codex

dspy-adapters-multimodal — Claude Code skill: setup and use

This skill guides DSPy adapter choices for structured responses, function calls, and image, audio, or document inputs. Use it when building DSPy-based AI applications.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add OmidZamani/dspy-skills --skill dspy-adapters-multimodal -a claude-code
Open on GitHub

What dspy-adapters-multimodal does

The skill explains how DSPy adapters affect model interaction and output formatting. ChatAdapter handles conversational text, JSONAdapter supports structured results and native function calling, and XMLAdapter presents fields using XML tags. TwoStepAdapter provides a separate extraction stage when a single pass is insufficient for parsing.

The examples cover adapter configuration through dspy.configure() and temporary overrides with dspy.context(). They also show how to define typed inputs with dspy.Image, dspy.Audio, and dspy.File. An image can come from a local path, an HTTP URL, raw bytes, a PIL image, or an existing data URI; audio and documents have their own loading methods.

Model support matters. DSPy uses manual parsing when the configured language model cannot perform native function calls. Check media support on the exact provider and model you plan to deploy. The skill also recommends calling dspy.Image(...) directly instead of relying on the deprecated Image.from_file() and Image.from_url() helpers.

What it helps with

  • Choose an adapter for structured JSON responses
  • Format prediction fields as XML
  • Pass a local image into a DSPy prediction
  • Summarize an audio recording or PDF
  • Handle models without native function calling

Example prompts for the agent

  • Configure JSONAdapter so my DSPy prediction returns structured data.
  • Show how to pass ./diagram.png through dspy.Image(...) and generate an image description.
  • Write a DSPy example that summarizes ./meeting.wav with dspy.Audio.from_file().

How to install dspy-adapters-multimodal

1Skills CLI (Vercel)

npx skills add OmidZamani/dspy-skills --skill dspy-adapters-multimodal -a claude-code

2Manually: put the files in place

~/.claude/skills/dspy-adapters-multimodal/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dspy-adapters-multimodal/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dspy-adapters-multimodal

How do I install dspy-adapters-multimodal in Claude Code?

Run npx skills add OmidZamani/dspy-skills --skill dspy-adapters-multimodal -a claude-code. The installed skill file is at ~/.claude/skills/dspy-adapters-multimodal/SKILL.md.

What does dspy-adapters-multimodal do?

It helps developers choose DSPy adapters and define typed media inputs. The guidance covers structured output, function calling, and passing images, audio, and files to a model.

Which DSPy adapters does the skill cover?

It covers ChatAdapter, JSONAdapter, XMLAdapter, and TwoStepAdapter. The right choice depends on the output format and model capabilities, which should be tested against the intended deployment model.

Source text

SKILL.md · MIT
---
name: dspy-adapters-multimodal
version: "1.0.0"
dspy-compatibility: "3.2.1"
tags: ["multimodal"]
requires-extras: []
description: Use for DSPy adapter selection, JSONAdapter, XMLAdapter, ChatAdapter, native function calling, structured outputs, and multimodal inputs like dspy.Image or dspy.Audio.
allowed-tools:
  - Read
  - Write
  - Glob
  - Grep
---

# DSPy Adapters and Multimodal I/O

## Goal

Choose an adapter deliberately and model image, audio, and file inputs with DSPy's typed primitives.

## Adapter Selection

| Adapter | Use it for |
|---------|------------|
| `dspy.ChatAdapter()` | Default, human-readable field markers, broad model compatibility |
| `dspy.JSONAdapter()` | Structured JSON output and native function calling where supported |
| `dspy.XMLAdapter()` | XML-tagged fields when XML is easier for the target LM to follow |
| `dspy.TwoStepAdapter()` | A separate extraction pass when parsing needs extra help |

Configure globally or for a limited scope:

```python
import dspy

dspy.configure(
    lm=dspy.LM("openai/gpt-4o-mini"),
    adapter=dspy.JSONAdapter(),
)

with dspy.context(adapter=dspy.XMLAdapter()):
    result = dspy.Predict("question -> answer")(question="What is DSPy?")
```

## Native Function Calling

`JSONAdapter` enables native function calling by default. `ChatAdapter` keeps text parsing by default. Override either behavior explicitly:

```python
chat_native = dspy.ChatAdapter(use_native_function_calling=True)
json_manual = dspy.JSONAdapter(use_native_function_calling=False)
```

DSPy falls back to manual parsing when the configured LM does not support native function calling.

## Image Inputs

```python
class DescribeImage(dspy.Signature):
    image: dspy.Image = dspy.InputField()
    description: str = dspy.OutputField()

describe = dspy.Predict(DescribeImage)
result = describe(image=dspy.Image("./diagram.png"))
```

Pass a local path, HTTP URL, bytes, PIL image, or existing data URI directly to `dspy.Image(...)`.

## Audio and File Inputs

```python
class SummarizeAudio(dspy.Signature):
    audio: dspy.Audio = dspy.InputField()
    summary: str = dspy.OutputField()

audio = dspy.Audio.from_file("./meeting.wav")
summary = dspy.Predict(SummarizeAudio)(audio=audio)
```

```python
class SummarizeFile(dspy.Signature):
    file: dspy.File = dspy.InputField()
    summary: str = dspy.OutputField()

document = dspy.File.from_path("./research.pdf")
summary = dspy.Predict(SummarizeFile)(file=document)
```

Provider capabilities vary. Verify that the selected model accepts the media type before deployment.

## Best Practices

1. Start with `ChatAdapter`; switch only for a measured reason.
2. Use typed signatures for structured output.
3. Test adapter behavior against the exact production model.
4. Avoid deprecated `Image.from_file()` and `Image.from_url()` helpers; call `dspy.Image(...)`.
5. Keep local file handling and uploaded file IDs within provider policy.

## Related Skills

- Design signatures: [dspy-signature-designer](../dspy-signature-designer/SKILL.md)
- Build tool agents: [dspy-react-agent-builder](../dspy-react-agent-builder/SKILL.md)

## Official Documentation

- **Adapters guide**: https://dspy.ai/learn/programming/adapters/
- **Tools guide**: https://dspy.ai/learn/programming/tools/
- **XMLAdapter API**: https://dspy.ai/api/adapters/XMLAdapter/
- **Image API**: https://dspy.ai/api/primitives/Image/
- **Audio API**: https://dspy.ai/api/primitives/Audio/

© OmidZamani · MIT · OmidZamani/dspy-skills

Similar skills

All skills for AI and ML →

From the same set23

dspy-finetune-bootstrap Turns a working DSPy program into fine-tuned weights for a smaller model, cutting inference cost and speeding up responses. CX Codex +1 ★ 124repo stars dspy-evaluation-suite Tests and benchmarks DSPy modules against evaluation datasets using multi-threaded execution and custom scoring functions. CX Codex +1 ★ 124repo stars dspy-embedding-retrieval Build semantic retrieval over an application-owned text corpus with DSPy embeddings, local or hosted models, and optional FAISS indexing. CX Codex +1 ★ 124repo stars dspy-debugging-observability A skill for debugging and monitoring DSPy programs: call history, MLflow tracing, and custom callbacks that track cost and errors. CX Codex +1 ★ 124repo stars dspy-custom-module-design Guides the creation of custom DSPy modules extending dspy.Module with state caching, input validation, and program serialization. CX Codex +1 ★ 124repo stars dspy-bootstrap-fewshot This skill guides BootstrapFewShot setup so a teacher model can generate demonstrations for a DSPy program. Use it when you have labeled examples and want to automate demo selection. CX Codex +1 ★ 124repo stars dspy-better-together A skill that walks you through chaining DSPy prompt and weight optimizers, scoring intermediate programs and keeping the best one. CX Codex +1 ★ 124repo stars dspy-advanced-module-composition Composes complex DSPy programs using module ensembling, MultiChainComparison, sequential pipelines, and fallbacks. Useful for multi-step reasoning architectures. CX Codex +1 ★ 124repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor