Skip to content

feat: integrate guardrails library with dual-mode support#45

Merged
initializ-mk merged 1 commit intomainfrom
security/guardrails
Apr 13, 2026
Merged

feat: integrate guardrails library with dual-mode support#45
initializ-mk merged 1 commit intomainfrom
security/guardrails

Conversation

@initializ-mk
Copy link
Copy Markdown
Contributor

Summary

  • Replace hand-rolled GuardrailEngine (435 lines of hardcoded patterns) with the external github.com/initializ/guardrails library, supporting dual-mode operation: file-based (guardrails.json) for local dev and MongoDB-backed for platform deployments with audit logging
  • Fix session recovery crash — orphaned tool calls (assistant tool_calls without matching tool results) are now stripped on both save and recovery, preventing "No tool output found for function call" API rejection
  • Fix inbound PII maskingCheckInbound was missing the DecisionMask handler, so PII (e.g. SSNs) passed through to the LLM unmasked
  • Fix SkillsStage early return — build stage now always scans skills/ subdirectory even without root SKILL.md, restoring binary installation (e.g. kubectl) for subdirectory-only skill projects
  • Update docs to reflect new guardrails architecture, configuration, and session recovery

Test plan

  • cd forge-core && go test ./...
  • cd forge-cli && go test ./...
  • forge init test-agent → verify guardrails.json generated with PII, security, secret rules
  • forge run → send SSN → verify inbound masking log and LLM never sees raw SSN
  • forge run → verify jailbreak prompt blocked in enforce mode
  • forge package on project with skills/ subdirectory (no root SKILL.md) → verify kubectl installed in container
  • Set FORGE_GUARDRAILS_DB → verify MongoDB config loading + audit logging
  • Kill agent mid-tool-call → restart → verify session recovery without API errors

…lls build stage

Replace the hand-rolled 435-line GuardrailEngine with the external
github.com/initializ/guardrails library. The new engine supports dual-mode
operation: file-based config (guardrails.json) for local development and
MongoDB-backed config for platform deployments with audit logging.

Key changes:
- forge-core: GuardrailChecker interface replaces concrete engine
- forge-cli: LibraryGuardrailEngine wraps guardrails.GuardrailManager
- forge-cli: BuildGuardrailChecker with DB → file → defaults priority
- forge init: generates guardrails.json with PII, security, and secret rules
- forge package: includes guardrails.json in container build context

Fix session recovery "No tool output found for function call" error:
- Memory.LoadFromStore sanitizes orphaned tool calls on recovery
- persistSession strips unanswered tool calls before writing
- Agent loop executes tool calls regardless of finish_reason

Fix CheckInbound missing DecisionMask handler — PII was passing
through to the LLM unmasked on inbound messages.

Fix SkillsStage early return when root SKILL.md is absent — the build
stage now always scans the skills/ subdirectory even without a root
SKILL.md, matching the runtime behavior. This restores binary
installation (e.g. kubectl) for projects using subdirectory skills.

Update docs to reflect new guardrails architecture, configuration,
and session recovery improvements.
@initializ-mk initializ-mk merged commit 6a514b6 into main Apr 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant