https://www.boundaryml.com logo
Customizable guardrails
# general
z
Any suggestions on "guardrail" type tooling? I need to be able to validate the output doesn't violate custom rules the user has specified. It seems likely that there should be some kind performance overhead, so needs to be minimal while still being accurate.
g
What kind of rules can the user specify? Depending on that, maybe some version of the user's rules could be passed as an argument to your BAML LLM function, and that argument could then be used in an @assert.
z
any arbitrary rule. like "do not talk about competitors", "do not offer old discounts", etc. Fair point about the @assert, I have not actually used it yet but will try it out. It may be sufficient here for now. I think in situations where there is a higher risk condition like prompt injection or PII redaction, then the validator tools(guardrailsAI,nemo,llm-guard,etc.) seem more prudent to use.
g
I agree with your point about PII redaction. For your case with an arbitrary user-defined function, I'm imagining a solution like this:
Copy code
class MyResponseType {
  my_normal_field int
  my_other_normal_field string
  // Add two fields to the return type for guardrail data.
  user_validation_ok bool @assert( {{ this }} )
  user_validation_reason string
}

function MyFunction(my_param_1: int, user_guard: string) {
  client "GPT5"
  prompt #"
    This is my normal prompt. It uses {{ my_param_1 }}.

    Additionally, indicate whether the data in the response
    satisfies this criterion:
    {{ user_guard }}, and indicate this to me through
    the user_validation_ok and user_validation_reason fields.
  "#
}
This approach works ok at first glance! I tired it out in promptfiddle here: https://www.promptfiddle.com/BAML-Examples-PsIh1
s
i build input and output guardrails as set of category validators (using llm or emb). each category is one (llm) or few (emb) descriptions and response in case of match. categories can be defined as negative belonging to them fails or positive - text must belongs to one category in a way to pass. build initial good/bad set of input/output text for validation. iterative improvements for emb: in generall adding to respective category text on which need to fail. llm improvement: 1. run validators on testing set collect info about i proper results ask llm to improve validation prompt. rerun review and update if better results 2. run validation set, collect info about most frequent invalid categories, ask llm to improve category description based on failed texts, rerun, update if improved. keep categories simple up to few sentences. some nonstandard usages: intent validation, inteligent static faq(category - user query, on fail text - answer) some improvemnt ideas introduced thanks to AI that works - tanks