[Idea]: RFC: Ray Serve LLM Governance Middleware Integration #477
Replies: 15 comments 5 replies
|
Thanks for the invite @nagasatish007 — joining from the cost-enforcement angle. My goal here is to help keep Four concrete interface suggestions: 1. Pre-dispatch budget enforcement only works if the hook can see estimated cost before the model runs. Suggest the context carry:
With those, an engine can compute worst-case cost = 2. Suggest: 3. Streaming: pre-dispatch is unaffected, but usage reconciliation matters Budget/velocity checks run in 4. Config scope + middleware ordering Agree with app-level + per-model. One addition: chain order should be explicit and deterministic (list order = execution order), so cheap checks (budget rules, sub-ms) can run before expensive ones (PII scanning) — a blocked request should never pay the scanning cost. Happy to build an AgentShield adapter against whatever interface comes out of this as a second reference engine — the pre-dispatch spend rules ( |
|
@kindrat86 — Great feedback. I'm taking all four points as design requirements, not optional. Summary of what i think needs implementing: RequestContext with cost-estimation inputs — model_id, estimated_input_tokens, max_tokens, tenant/session identifiers Next steps: Finalize the interface definition here (you, @nagasatish007, and any Ray maintainers watching) |
|
@nagasatish007 — Ray just assigned this to @richardliaw at Anyscale. I've posted on the main issue asking about implementation expectations. Will sync here as we move toward the RFC PR. |
|
@Divyam19 — appreciate you treating all four as requirements. That summary is exactly the interface I had in mind. On the plan: finalize interface here → PR base What I'll bring when the interface draft lands: AgentShield's 7 rule types all map to
I'll sketch the Also worth noting: Ray assigned the issue to @richardliaw at Anyscale — that's about as good an assignment signal as we could hope for. The interface needs to be tight when it reaches his desk. I'll watch this thread. Tag me when the draft hooks are up. |
|
@Divyam19 — this summary is exactly right. All four points as stated. On the AgentShield side, the mapping is straightforward — all 7 rule types slot cleanly into two hooks:
Happy to sketch the @nagasatish007 — your call on when the interface draft is ready for the next review round. |
|
Great progress here. @kindrat86's four design requirements are exactly right — adopting all of them. On the interface draft, here's where TealTiger maps to the proposed hooks:
On ordering: agree completely. TealTiger's policy evaluation is sub-ms (fnmatch + regex), so it belongs early in the chain. PII scanning is the most expensive check (~1ms for 40 patterns) and should run last among our policies. The explicit list-order-equals-execution-order design handles this naturally. On Next step from my side: once @Divyam19 posts the draft hook signatures, I'll write the The two-engine validation (TealTiger for PII/content, AgentShield for cost enforcement) is the strongest possible signal to @richardliaw that the abstraction is vendor-neutral. Let's make sure both adapters exist before the RFC reaches his desk. |
|
@nagasatish007 @kindrat86 — did the R&D. Went through How it works in practiceRay already supports custom ingress classes through All three hooks live inside
Context availabilityMapped the
Streaming approachv1 is audit-only. Generator gets wrapped, chunks pass through to the client untouched, we accumulate text + usage as they flow, If someone needs to redact secrets from the response before the client sees them — that requires buffering the entire response, which kills streaming. That's a v2 opt-in with explicit latency tradeoffs documented. Scope clarificationWant to make sure we're not stepping on each other — I'm handling the Ray-side work: What's next from meDraft hook signatures this week, will post here for review. Once we're aligned, I'll open a draft PR on Ray. @kindrat86 — on your question about |
|
@Divyam19 — solid breakdown, thanks for mapping it all out. On the token estimate question: rough estimate is fine for AgentShield's pre-dispatch. We're a firewall, not an auditor — the job is catching obvious over-spend before it happens, not precise billing. Character-count ÷ 4 gets us close enough for the blocking threshold. Accurate reconciliation in That said, if someone else (TealTiger?) needs precision at the ingress, option (b) — loading the tokenizer — is the right call. Happy to keep it optional/configurable so each middleware adapter picks its own strategy. Re: next steps — your plan sounds right. I'll sketch the AgentShield adapter once the hook signatures are up for review. No rush on my side. |
|
@Divyam19 Sounds good. I will work on Tealtiger's end. Go ahead with your plan. |
|
@kindrat86 @Divyam19 Please join TealTiger Discord at : https://discord.gg/ZnCEd5Mk2 and award github star too, if that is not a big ask :) |
|
Yes — Discord name is Maryan (maryan_33221). Joined and starred 👍 |
|
@kindrat86 @nagasatish007 I have raised the pr for hooks please go through it once to understand what I have done. Ur review will help. Also I'll try to get it merged, facing a micro check issue rn. On the CI. Working on that. |
|
Took a proper look at the PR (ray-project/ray#65514), good work @Divyam19. All four points from this thread landed in the interface: structured 1. Error handling is asymmetric across the chain. 2. 3. One more doc suggestion: state explicitly in the streaming section that Planning to point the AgentShield adapter at this branch once the interface settles. Anything it can't express will come back here as concrete issues. |
|
@Divyam19 — went through ray-project/ray#65514. This is solid work. All four design requirements from this thread are represented in the interface, the commit structure is clean (one concern per commit), and the test coverage is thorough — unit tests, mocked-handle ingress, and HTTP e2e. Labels ( Feedback on @kindrat86's three points, from the TealTiger adapter perspective: Point 1: Error handling —
|
| Who | Action |
|---|---|
| @Divyam19 | Fix kindrat86's 3 points (error handling, estimated_input_tokens, headers warning in docs) |
| @nagasatish007 | Begin ray-tealtiger adapter against Divyam19's branch |
| @kindrat86 | Begin agentshield-ray adapter against same branch |
| All | Reconvene once both adapters exercise the hooks — file concrete issues for anything that doesn't fit |
|
@nagasatish007: all three points are settled from my side, no changes:
One addition from the cost-enforcement side, on On streaming: agree v1 is audit-only, no buffering. For AgentShield this is a non-issue at dispatch (spend checks run in Action item confirmed: I'll start the |
Uh oh!
There was an error while loading. Please reload this page.
Your Idea
A community contributor (@Divyam19) volunteered on Ray issue #65259 to implement a governance middleware layer for Ray Serve LLM. They proposed TealTiger as the reference integration behind a backend-agnostic
LLMMiddlewareinterface in Ray.This discussion is to collaborate on the interface design before submitting an RFC/PR to Ray.
Proposed architecture:
LLMMiddlewareinterface (lives in Ray) — typed hooks at the semantic LLM request layer:before_inference(request, context) → request | BlockedResponseafter_inference(request, response, context) → responseon_stream_chunk(chunk, context) → chunk | None(optional)ray-tealtigerpackage (lives here) — reference implementation wrapping TealTiger's engine behind the interface. PII scanning, cost budgets, model access policies, audit receipts. Zero-LLM governance path.Open design questions for the RFC:
LLMConfig.middleware?Category
Integration
What problem does this solve?
Ray Serve LLM has no built-in governance/guardrails layer. Teams in regulated industries (healthcare, finance, government) currently have to either build custom deployments from scratch or add a separate proxy in front of Ray — losing all benefits of LLMRouter, autoscaling, and multi-model management. A middleware layer lets them use the standard
LLMConfigpipeline with governance built in.Potential Impact
Implementation Thoughts
LLMMiddlewarehooks is straightforwardExamples or References
All reactions