Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Problem
Currently, DSRs serializes input field values using a simple approach:
- Strings → raw string
- Everything else →
serde_json::to_string()
This differs from DSPy's ChatAdapter which has special formatting for certain types (e.g., «blob» markers for string lists). More importantly, we already have BAML's serialization infrastructure (internal_baml_jinja with format filters for yaml/json/toon) but we're not using it for input formatting.
What We Want
Goal API
#[derive(Signature, Clone)]
struct RAG {
#[input]
question: String,
#[input]
#[format("yaml")] // or "json", "toon", etc.
context: Vec<Document>,
#[output]
answer: String,
}When context is serialized for the LLM prompt, it should use BAML's format infrastructure—the same one used for output schema rendering—to serialize the value.
Expected Behavior
| Format | Serialization |
|---|---|
"json" |
Compact JSON (current default) |
"yaml" |
Human-readable YAML |
"toon" |
Token-efficient TOON format for uniform arrays |
Why BAML Infrastructure?
- Consistency - Same serializers used for output schemas
- Alias preservation - BAML's serializers respect
@aliason enums/classes - TOON support - Token-efficient format for tabular data (significant savings)
- Already available -
internal_baml_jinjais already a dependency
Current State
crates/dspy-rs/src/adapter/chat.rs:504-510-format_baml_value_for_prompt()does basic JSONbaml_bridge::internal_baml_jinja- Has format filters but not wired up for input serialization- Output schemas already use
OutputFormatContent::render()withRenderOptions
Investigation Needed
- How to invoke BAML's format filter programmatically (not via template string)
- Where the filter is defined in
internal_baml_jinja - Whether we can call it directly on
BamlValue
Acceptance Criteria
-
#[format("yaml")]attribute works on input fields -
#[format("json")]attribute works (explicit, same as default) -
#[format("toon")]attribute works for uniform arrays - Uses BAML's existing infrastructure, not a separate serde_yaml dependency
- Aliases are preserved in serialized output
References
- BAML Jinja Filters docs: https://docs.boundaryml.com/docs/calling-baml/jinja-filters
- DSPy ChatAdapter:
dspy/adapters/chat_adapter.py - DSPy BAMLAdapter:
dspy/adapters/baml_adapter.py
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity