Prompting Safely: Building Secure LLM Prompts with a Scala DSL
summary
Scala DSL that composes prompts via a typelevel interpolator and contravariant templates, implemented in about 300 lines, built over three months and flagged not production ready. It uses Cats IO monad for validation which runs on the final rendered prompt and can call databases or a secondary LLM to block prompt injection. Templates are a contravariant Template typeclass and the library can request structured JSON outputs using serializers like Circe / Play / ZIO Schema to model case classes.
AI-written summary · about
chapters (12)
- 0:00Prompt safety introduction
- 1:25Why prompt safety matters
- 2:52Scala DSL design
- 7:55Prompt library goals
- 13:09Library implementation basics
- 18:25Advanced combinators
- 23:06Prompt interpolator
- 27:22Validating prompts
- 30:12Prompt formatting
- 31:59Summary and future work
- 34:13Trade-offs and injection protection
- 35:42Closing remarks
related talks
32mSafer Code with LLMs: Scala Types Silver Bullet?
30mEfficient programming with Scala and LLMs
35mFrom Zero to Three - Building a User Friendly DSL with Scala 3
48mBeyond the Prompt: Evaluating, Testing, and Securing LLM Applications
40mSafe Coding with LLMs - Verifiable Scala Silver Bullet
42mWhen your DSL Needs to Support User-Defined Functions
41mTeaching Domain Specific Languages in Scala
32mSimple and Speedy UIs in Scala 3
