Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for input data validation #167

Open
bala-pitchuka opened this issue May 21, 2024 · 5 comments · May be fixed by #267
Open

Support for input data validation #167

bala-pitchuka opened this issue May 21, 2024 · 5 comments · May be fixed by #267
Assignees
Labels
enhancement New feature or request

Comments

@bala-pitchuka
Copy link

bala-pitchuka commented May 21, 2024

Hi,

Just want to check if there is an existing mechanism to check that all mandatory fields are provided to zen engine without missing during evaluation.

like a sample rule if threshold > 23 then HOLD

if threshold is not provided as input to zen then them some validation error need to be thrown

Also how to check the json is a valid jdm json before execution currently facing following issue when run, just want to eliminate such issues during rule jdm json creation itself

RuntimeError: {"type":"NodeError","nodeId":"","source":"Graph did not halt. Missing output node."}

thnks

@stefan-gorules
Copy link
Contributor

Hi @bala-pitchuka,

We have some initial plans of looking into type-safety in the future. Our foundation will rest on a dynamic language - ZEN Expressions that will be enhanced with type support at some point.

For now, most common pattern is to do validation of the data before sending it to the rules engine. Depending on the language used, there are some great options: Zod (TypeScript), Validator (Go), validator (Rust crate), etc.

@stefan-gorules stefan-gorules added the enhancement New feature or request label Jun 24, 2024
@stefan-gorules
Copy link
Contributor

Hi @bala-pitchuka

This is something that will be possible with Function v2 through usage of Zod. We will provide an example in docs soon.

@stefan-gorules stefan-gorules self-assigned this Jul 17, 2024
@Aakarshan-369
Copy link

Hi @stefan-gorules !

I have been exploring the ZenEngine library in Node for a in-house BRMS prototype. Firstly great work on the library! it has intuitive semantics and is very performant as well.
I am having trouble figuring out how to validate a string as a valid Zen Expression syntactically. Before re-instantiating a engine with a new schema I wanted to make sure the changes in a rule row's inputs and outputs are valid Zen syntax.

if I'm approaching this incorrectly please suggest a way!

@bala-pitchuka
Copy link
Author

Hi @bala-pitchuka

This is something that will be possible with Function v2 through usage of Zod. We will provide an example in docs soon.

@stefan-gorules docs would be great to explore the same, thnks

@Gabrieltay
Copy link

hi @bala-pitchuka , with Function v2, just an simple example here

import { z } from "zod";

/* input
{
  age: 20,
  salary: 3000.25,
  name: "John"
}
*/
export const handler = async (input) => {
  const schema = z.object({
    age: z.number()
      .min(15, { message: "Age must be at least 15" })
      .max(60, { message: "Age must be at most 60" }),

    salary: z.number()
      .nonnegative({ message: "Salary must be non-negative" })
      .refine(value => value.toFixed(2) === value.toString(), {
        message: "Salary must have up to 2 decimal places"
      }),
  });

  const result = schema.safeParse(input);
  if (result.success) {
    return result.data
  } else {
    console.log(result.error)
    return {}
  }
};

@stefan-gorules stefan-gorules linked a pull request Oct 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants