Close Menu
  • AI
  • Content Creation
  • Tech
  • Robotics
AI-trends.todayAI-trends.today
  • AI
  • Content Creation
  • Tech
  • Robotics
Trending
  • OpenRouter Cuts Three Suppliers After AI Immediate Publicity Findings – Unite.AI
  • A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels
  • Collectively AI Discloses Immediate Leak After Coding Agent Uncovered Credential – Unite.AI
  • Dragos Finds Immediate Leaks and Stolen Keys in AI Provide Chains
  • Lean and Mathlib Communities Certify Claude-Assisted Riemann Proof – Unite.AI
  • AWS Routes HyperPod Inference Throughout Areas From One Endpoint – Unite.AI
  • DailyAI Briefing: A Lean-checked Riemann proof, plus 4 extra
  • Anthropic Shares Drop 8.5% in Second Session Throughout AI Selloff – Unite.AI
AI-trends.todayAI-trends.today
Home»Tech»Create, validate, and rank Python functions using unit tests, safety checks, and Salesforce CodeGen.

Create, validate, and rank Python functions using unit tests, safety checks, and Salesforce CodeGen.

Tech By Gavin Wallace19/06/20263 Mins Read
Facebook Twitter LinkedIn Email
This AI Paper Introduces MMaDA: A Unified Multimodal Diffusion Model
This AI Paper Introduces MMaDA: A Unified Multimodal Diffusion Model
Share
Facebook Twitter LinkedIn Email
def extract_function_source(full_text, function_name):
 Replace text with full_text (text = "full_text")"rn", "n")
 Search for fence (r)"```(?:python)?n(.*?)```", text, flags=re.S | re.I)
 Fence:
 Text = fence.group(1)
 Pattern = rf"^defs+{re.escape(function_name)}s*("
 Match = re.search()(pattern text flags=re.M)
 Not matching:
 You can return to your original language by clicking here. ""
 Text chunk[match.start():]
   lines = chunk.splitlines()
  []
 For i, the line of enumerate (lines):
       if i > 0:
 if line.startswith."def "Line.startswith ("class "):
 Breaking News
 If line.startswith ("if __name__"):
 Breaks
 If line.startswith and line.startswith is not true, then line.startswith ((" ", "t", "#"() and match(r"^[A-Za-z_][A-Za-z0-9_]*s*=", line):
 Break the Rules
       collected.append(line)
   source = "n".join(collected).rstrip()
   try:
       ast.parse(source)
       return source
 SyntaxError is not allowed:
       fixed_lines = []
 Line in collect:
           fixed_lines.append(line)
 Candidate = "n".join(fixed_lines).rstrip()
           try:
               ast.parse(candidate)
 source = candidate
 Except SyntaxError
               pass
       return source if source.strip().startswith("def "If ( ) then ""
Def syntax_ok (source)
   try:
       ast.parse(source)
 return True ""
   except SyntaxError as e:
 Return False str(e)
FORBIDDEN_NAMES = {
   "eval", "exec", "compile", "open", "input", "__import__",
   "globals", "locals", "vars", "dir", "getattr", "setattr", "delattr",
   "help", "breakpoint", "exit", "quit"
}
FORBIDDEN_NODES = (
   ast.Import,
   ast.ImportFrom,
   ast.Global,
   ast.Nonlocal,
   ast.With,
   ast.AsyncWith,
   ast.AsyncFunctionDef,
   ast.ClassDef,
   ast.Delete,
   ast.Raise,
)
ALLOWED_BUILTINS = {
   "abs": abs,
   "all": all,
   "any": any,
   "bool": bool,
   "dict": dict,
   "enumerate": enumerate,
   "float": float,
   "int": int,
   "isinstance": isinstance,
   "len": len,
   "list": list,
   "map": map,
   "max": max,
   "min": min,
   "pow": pow,
   "range": range,
   "reversed": reversed,
   "round": round,
   "set": set,
   "sorted": sorted,
   "str": str,
   "sum": sum,
   "tuple": tuple,
   "zip": zip,
}
def static_safety_check(source):
   try:
 Source = tree
   except SyntaxError as e:
 False"SyntaxError: {e}"
 Node of ast.walk (tree)
 if isinstance (node FORBIDDEN_NODES);
 Return False"Forbidden AST node: {type(node).__name__}"
 If isinstance (node ast.Name), then:
 If node.id appears in FORBIDDEN_NAMES (or node.id.startswith)"__"):
 Return False"Forbidden name: {node.id}"
 If isinstance (node or ast.Attribute), then:
           if node.attr.startswith("__"):
 Return False"Forbidden attribute: {node.attr}"
 if isinstance (node)(ast.Call).
           if isinstance(node.func, ast.Name) and node.func.id in FORBIDDEN_NAMES:
 False"Forbidden call: {node.func.id}"
 Return True "passed"
def _worker_run_tests(source, function_name, tests, queue):
   try:
       safe_globals = {"__builtins__": ALLOWED_BUILTINS}
       safe_locals = {}
 Source = compile (source) "", "exec")
       exec(compiled, safe_globals, safe_locals)
       fn = safe_locals.get(function_name) or safe_globals.get(function_name)
 If fn = None
           queue.put({"ok": False, "error"""{function_name} not found", "passed": 0, "total": len(tests)})
 Return to the Homepage
 passed = 0
       details = []
 Tests:
 Test.get(args)"args", [])
 Test.get kwargs"kwargs", {})
 Expected = test["expected"]
           result = fn(*args, **kwargs)
 OK = expected = = = = = = == ===============================?
 = passed + int
           details.append({
               "args": args,
               "kwargs": kwargs,
               "expected": expected,
               "result": result,
               "ok": ok,
           })
       queue.put({"ok"Len == passed "error": "", "passed": passed, "total": len(tests), "details": details})
 Except Exception As e.
       queue.put({"ok": False, "error": repr(e), "passed": 0, "total": len(tests)})
def run_unit_tests_safely(source, function_name, tests, timeout_seconds=3):
   safe, reason = static_safety_check(source)
 unless you are safeReturn
       return {"ok": False, "error": reason, "passed": 0, "total": len(tests), "details": []}
 Get context by ctx."fork")
   queue = ctx.Queue()
   process = ctx.Process(target=_worker_run_tests, args=(source, function_name, tests, queue))
   process.start()
   process.join(timeout_seconds)
 If the process.is_aliveReturnReturn():
       process.terminate()
       process.join()
       return {"ok": False, "error": "timeout", "passed": 0, "total": len(tests), "details": []}
   if queue.empty():
       return {"ok": False, "error": "no result returned", "passed": 0, "total": len(tests), "details": []}
   return queue.get()
def code_complexity(source):
   try:
 Blocks = cc_visit (source)
 If you do not want to block:
 Return 1
 Return max(block.complexity of block for blocks in blocks).
 The exception:
 Return No
def score_candidate(source, test_result):
 If syntax_ok (source), then syntax_score is 1.[0] Other 0
   safety_score = 1 if static_safety_check(source)[0] Other 0
 Test_result.get()"passed", 0)
   total = max(test_result.get("total", 1), 1)
 Test_score is the result of the test.
   complexity = code_complexity(source)
 Complexity_penalty = 0 when complexity is none else min(complexity/20, 0.25).
   return syntax_score + safety_score + 3 * test_score - complexity_penalty
code dat safety salesforce
Share. Facebook Twitter LinkedIn Email
Avatar
Gavin Wallace

Related Posts

A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels

22/11/2026

OpenAI Ships GPT-Stay-1.1 for Voice Brokers, Cuts Idle Value to $0.02/Min

21/11/2026

Meet Pondering Machines Inkling 2 Mini: 26B Looped MoE Runs on a 32GB Mac

21/11/2026

Baseten Releases Bison-1 and Groundhog-1, Topping Choice Mannequin Index

21/11/2026
Top News

OpenAI loses another high-profile researcher to Meta

SweetREX, a DOGE AI tool called SweetREX is coming to reduce US government regulations

Spooky New Infostealer Malware Makes use of AI to ‘Autodox’ Victims

AI Slop is Ruining Reddit and Reddit for All

Jensen Huang’s Imaginative and prescient for Europe Runs on Plug-In Information Facilities

Load More
AI-Trends.Today

Your daily source of AI news and trends. Stay up to date with everything AI and automation!

X (Twitter) Instagram
Top Insights

Liquid AI Releases d1.2 and d1.2-ultra: Omnimodal Determination Fashions That High the AA Determination Index

17/11/2026

Perplexity releases pplx – a single binary CLI that puts its Search API into the terminal for Coding Agents

27/07/2026
Latest News

OpenRouter Cuts Three Suppliers After AI Immediate Publicity Findings – Unite.AI

22/11/2026

A Group of Researchers from Columbia and CertiK Introduce TensorLean for Formal Verification of GPU Kernels

22/11/2026
X (Twitter) Instagram
  • Privacy Policy
  • Contact Us
  • Terms and Conditions
© 2026 AI-Trends.Today

Type above and press Enter to search. Press Esc to cancel.