feat: add composable guardrails for TACTool (rate limiting) - #86
Open
yatharth-1504 wants to merge 2 commits into
Open
feat: add composable guardrails for TACTool (rate limiting)#86yatharth-1504 wants to merge 2 commits into
yatharth-1504 wants to merge 2 commits into
Conversation
yatharth-1504
requested review from
ryanrishi,
ryanrouleau and
xinghaohuang91
as code owners
August 27, 2026 11:48
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an initial “guardrails” foundation to the packages/tools package by introducing a typed GuardrailError and an in-memory sliding-window rate limiter intended to run before a TACTool implementation executes.
Changes:
- Introduces
GuardrailErrorwith a discriminatingtype(rate_limit/content_filter) for guardrail failures. - Adds
SlidingWindowRateLimiter(per-key, in-memory) to enforce call limits within a time window. - Adds Vitest coverage for the new error type and rate-limiter behavior, and exports
GuardrailErrorfrom the tools package entrypoint.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/rate-limiter.test.ts | Adds unit tests for sliding-window rate limiting behavior (limits, reset, per-key isolation). |
| tests/guardrails.test.ts | Adds unit tests for GuardrailError shape (name, message, type). |
| packages/tools/src/lib/rate-limiter.ts | Introduces SlidingWindowRateLimiter implementation for rate limiting guardrails. |
| packages/tools/src/lib/errors.ts | Adds GuardrailError used to signal guardrail blocks. |
| packages/tools/src/index.ts | Exports GuardrailError from the tools package public API. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+9
to
+13
| export class SlidingWindowRateLimiter<TParams> { | ||
| private readonly timestamps: Map<string, number[]> = new Map(); | ||
|
|
||
| constructor(private readonly config: RateLimitConfig<TParams>) {} | ||
|
|
| } | ||
|
|
||
| export class SlidingWindowRateLimiter<TParams> { | ||
| private readonly timestamps: Map<string, number[]> = new Map(); |
| @@ -0,0 +1,30 @@ | |||
| import { GuardrailError } from './errors.js'; | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a composable guardrail system to
packages/toolsthat lets developers wrap anyTACToolwith rate limiting before the tool's implementation runs. This is the foundation for a broader guardrail system (content filtering +withGuardrails()wrapper coming in a follow-up PR).New files:
packages/tools/src/lib/errors.ts—GuardrailErrorwith atypefield ('rate_limit' | 'content_filter')packages/tools/src/lib/rate-limiter.ts—SlidingWindowRateLimiter(sliding window, in-memory, per-key)Modified:
packages/tools/src/index.ts— exportsGuardrailErrorpubliclyUsage preview (once
withGuardrails()lands in the follow-up):When the limit is exceeded,
GuardrailErroris thrown — LLM SDKs surface this as a tool-result message so the model can respond gracefully ("I've sent too many messages, please wait a moment").Type of Change
Checklist
SDK Parity