promptflow icon indicating copy to clipboard operation
promptflow copied to clipboard

[Feature Request] Token-efficient serialization for flow execution to reduce LLM context overhead

Open makroumi opened this issue 7 months ago • 3 comments

Is your feature request related to a problem? Please describe. Promptflow serializes node inputs, outputs, and inter-node data as JSON throughout flow execution. At scale this creates measurable and expensive overhead that compounds with flow complexity.

~44% of tokens in typical LLM flow payloads are pure JSON syntax overhead before any reasoning begins. Brackets. Repeated key names. Whitespace. None of it is intelligence. All of it costs money.

Promptflow flows are particularly exposed because:

  1. Each node receives its full input context serialized as JSON on every execution

  2. LLM nodes receive JSON-wrapped prompts adding syntax overhead before token counting

  3. Multi-turn chat flows accumulate JSON history overhead across every turn

  4. Batch runs multiply this overhead across every row in the dataset

  5. Evaluation flows add another JSON serialization layer on top of results

At 10M flow executions on GPT-4o: ~$59K spent on syntax noise. Not reasoning.

For enterprise Promptflow deployments running continuous batch evaluation this is a significant and invisible cost driver.

Describe the solution you'd like A pluggable serialization interface in Promptflow's execution engine allowing token-efficient formats as opt-in replacement for JSON at the node communication layer.

I built ULMEN specifically for this problem.

Benchmarks on NVIDIA Tesla T4 production hardware:

Image

Beyond token reduction, ULMEN adds a Semantic Firewall that validates flow state transitions:

  • Rejects invalid node output schemas
  • Catches malformed inter-node payloads
  • Validates enum fields before LLM sees them
  • Raises structured errors vs silent failures

Silent node failures passing through JSON undetected cause downstream LLM nodes to reason on broken context - a common source of evaluation errors that are hard to diagnose.

Proposed implementation - opt-in at flow level:

# flow.dag.yaml
node_serializer: ulmen  # opt-in, default: json

# Or per-node
nodes:
- name: my_llm_node
  type: llm
  serializer: ulmen

# Python SDK
with Flow("my_flow.dag.yaml") as f:
    f.run(
        data="data.jsonl",
        serializer="ulmen"
    )

ULMEN is:

  • Drop-in Python/Rust library
  • No schema compilation required
  • Pure Python fallback if Rust unavailable
  • Byte-identical output Python vs Rust
  • BSL license, free under $10M revenue
  • 1,364 tests, 100% statement coverage

Particularly valuable for Promptflow's batch run mode where the overhead multiplies across every row in the dataset simultaneously.

Reproducible benchmark notebook: github.com/makroumi/ulmen

Happy to submit a PR once maintainers confirm preferred integration approach.

Describe alternatives you've considered

  1. orjson Faster serialization but identical token count. Context window overhead unchanged. Doesn't address the core problem.

  2. Manual prompt compression Lossy. Requires custom logic per flow node. Breaks when schemas change. Not systematic.

  3. Reducing batch size Trades throughput for cost. Wrong tradeoff for production batch runs.

  4. Smaller models per node Reduces capability not just overhead. Wrong lever for serialization waste.

ULMEN addresses the root cause: JSON was designed for web APIs not LLM flow execution engines. ULMEN was designed specifically for LLM context window constraints from the ground up.

Additional context Promptflow's batch run and evaluation modes are the highest-impact targets because:

  1. Batch runs multiply overhead across every dataset row simultaneously
  2. Evaluation flows add a second serialization layer on top of already-overhead LLM outputs
  3. CI/CD evaluation pipelines run continuously making the cost compound over time
  4. Azure AI Studio deployments at enterprise scale make this a significant line item

A 44% token reduction on batch evaluation runs means:

  • 44% more rows evaluated for same budget
  • 44% faster batch completion at same cost
  • Direct improvement in CI/CD economics

This is uniquely synergistic with Promptflow's batch evaluation mission in a way that applies to every flow regardless of domain.

Reproducible benchmark notebook: github.com/makroumi/ulmen

makroumi avatar Apr 15 '26 18:04 makroumi

Hi, we're sending this friendly reminder because we haven't heard back from you in 30 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 7 days of this comment, the issue will be automatically closed. Thank you!

github-actions[bot] avatar May 15 '26 21:05 github-actions[bot]

Still relevant. Bumping this for maintainer visibility. Benchmarks showing 44% improvement are still live at the link above.

makroumi avatar May 16 '26 00:05 makroumi

Hi, we're sending this friendly reminder because we haven't heard back from you in 30 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 7 days of this comment, the issue will be automatically closed. Thank you!

github-actions[bot] avatar Jun 15 '26 22:06 github-actions[bot]