Skip to content

investigate top-level guardian intrinsic functions to remove prompt formatting #1017

Closed

Description

@jakelorocco

The guardian intrinsic functions mellea/stdlib/components/intrinsic/guardian.py do a bunch of prompt / string mangling. This means that the regular implementation of Intrinsics don't benefit from the correct formatting; ie:

out, _ = mfuncs.act(Intrinsic("guardian"),....)

We should see if it's feasible to move the necessary prompting into the Intrinsic itself / io.yaml file so that we don't force people into the top-level helper functions.

Activity

  1. jakelorocco commented on May 5, 2026

    @jakelorocco
    ContributorAuthor

    fyi @ink-pad, I believe you are the right person to ping about this. We will investigate from our side to start though.

  2. changed the title [-]investigate top-level guardian intrinsic functions[/-] [+]investigate top-level guardian intrinsic functions to remove prompt formatting[/+] on May 5, 2026
  3. ink-pad commented on May 5, 2026

    @ink-pad
    Contributor

    Looping in @subhajitchaudhury, as he owns this intrinsic integration piece.

  4. added this to the Release 0.6.0 milestone on May 6, 2026
  5. self-assigned this
    on May 6, 2026
  6. psschwei commented on May 7, 2026

    @psschwei
    Contributor

    Just to make sure I'm understanding the issue correctly:

    Right now, we have helper functions for calling each intrinsic. For example, guardian-check(). The guardian ones are particular in that they wrap the user's message in the appropriate "envelope" for the guardian intrinsic.

    We want to also allow folks to be able to call the intrinsics directly from something like mfuncs.act(Intrinsic("guardian-check"),....) but the problem is that this route does not get the "envelope" and so the guardian check will not work on this route.

    To fix this issue, we need to get the proper envelope on the raw message so that we can use it in the mfuncs.act(Intrinsic(...),...) pattern.

    So far so good?

    Assuming so, one way to go about this would be to update the HF io.yaml file for each intrinsic, so that the instruction block would have the appropriate envelope. For example, for guardian-check we could do:

      instruction: |-
        <guardian>As a judge agent, your role is to help assess whether the provided text meets the given judging criteria, utilizing
      all available information, including conversations, documents, and tools.
    
        ### Criteria: {criteria}
    
        ### Scoring Schema: {scoring_schema}

    As that would require upstream changes which may or may not be easy to land, another option could be to attach a per-intrinsic envelope builder to the Intrinsic component via a class-level registry. The backend dispatch path calls it to append the envelope when rendering the context. This would also pull the envelope wrapping out of the helper functions. This could be done independently of the upstream io.yaml changes (and then dropped when those upstream changes happen).

    The benefit of the second approach is that we can decouple from the upstream dependency: it would let us make the Mellea updates independently of the upstream ones. Whether that's something we want to do would probably ultimately depend on how long it would take to get the upstream changes in (as I assume changing the template would be a breaking change, my guess is it would probably require a model version bump, though someone should confirm that).

    @jakelorocco is that an accurate assessment of the issue? And any opinions on the two approaches I laid out (I assume it mostly comes down to timing: second approach we control completely, but the first one while cleaner has external dependencies)?

    @ink-pad @subhajitchaudhury are my assumptions about what would be needed upstream at least aiming in the right direction?

  7. pronics2004 commented on May 7, 2026

    @pronics2004
    Contributor

    Confirming I'm reading this the same way — the problem is that the ... envelope (system prompt + criteria + scoring schema) is constructed in Python inside the helpers (guardian_check, policy_guardrails, factuality_detection, factuality_correction) and injected as a user message right before call_intrinsic. So
    mfuncs.act(Intrinsic("guardian-core"), ...) sends an unwrapped request and the adapter misbehaves.

    Option A — envelope in io.yaml (upstream).
    Move the preamble into instruction: on each guardian's HF model card. IntrinsicsRewriter already .format(**kwargs) the instruction and appends it as a user message, so the machinery is in place. Guardian-core would parameterize {criteria} (and probably {target_role}); policy-guardrails would parameterize {policy_text}; factuality-detection/correction are
    fully static and drop straight in.

    Should not require model version bump I think, Requires re-signing io.yamls after co-ordinating with everyone on the change.

    Option B — envelope registry in Mellea.
    Per-intrinsic envelope builder keyed by intrinsic name; backend dispatch (_generate_from_intrinsic in huggingface.py and openai.py) calls it before IntrinsicsRewriter runs.

    Only Mellea change, no external dependency; retirable entry-by-entry as upstream io.yamls get populated.

    Suggestion: do both, staged. Option B now so mfuncs.act(Intrinsic("guardian-core"), ...) works and the helpers simplify. Option A in parallel — factuality-detection/factuality-correction are the zero-risk first targets (static envelopes, no parameters). Delete registry entries as their upstream YAMLs land.

    @jakelorocco @psschwei does this match your understanding? Between A+B staged vs. B-only vs. A-only, any preference?

  8. psschwei commented on May 7, 2026

    @psschwei
    Contributor

    Should not require model version bump I think, Requires re-signing io.yamls after co-ordinating with everyone on the change.

    Cool, this is good to know (I wasn't very familiar with how we version model artifacts)

    @jakelorocco @psschwei does this match your understanding?

    Yes it does.

    Between A+B staged vs. B-only vs. A-only, any preference?

    I believe we are targeting a patch release in the near future (@jakelorocco keep me honest here), so I think a staged approach might make sense in that scenario, as that would let us get this in sooner (not sure how long it would take to coordinate the resigns, but assuming post-4.1 release we all slow down a little bit 😄 ). May come down to a question of timing.

    Though one question here: once the upstream io.yaml changes, we would need to concurrently disable the wrapper in Mellea, right? because otherwise we'd be double-wrapping... hmmm... I wonder if we can gate the wrapper on the Mellea side somehow (only use if message doesn't start with <guardian>?) ... may need to think on it a bit more.

    per Jake's comment below, preferred approach is Option A (envelope upstream)

  9. jakelorocco commented on May 7, 2026

    @jakelorocco
    ContributorAuthor

    My preferred solution here would be to get the io.yaml approach working. If @pronics2004 / we can get a version of the io.yaml that works, we could likely just change the default one that gets used by our code.

    I think that this code path is so infrequently used (we only really show calling intrinsics through the top level helper functions), that forcing us to write awkward wrapper / gated code on the Mellea side and then potentially hit coordination issues with the intrinsic is too much effort.

  10. psschwei commented on May 7, 2026

    @psschwei
    Contributor

    Would we still need to coordinate on when to remove the existing wrappers in the helper functions? If the instruction block is populated upstream, the wrapper in the helper would be redundant right?

  11. psschwei commented on May 7, 2026

    @psschwei
    Contributor

    Also, just to check, will the upstream update happen in just the last model (4.1) ? And if so, would that impact the versions we can support?

    (sorry if these are silly questions, I'm still learning how this area works)

  12. jakelorocco commented on May 7, 2026

    @jakelorocco
    ContributorAuthor

    If we do io.yaml overrides, we would still need to remove the block post upstream change, but we wouldn't have any coordination timing issues; it would be a basic before / after.

    Yes, that's a good point. We would have to make sure the io.yaml's are changed for all of the guardian adapter versions that we support (given the fact that we don't have great versioning in Mellea for this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions