---
url: 'https://sema-lang.com/docs/stdlib/reflect.md'
---

# Reflection & Diagnostics

Parse, format, and check Sema source from Sema. Diagnostics come back as data,
which makes them ideal for agent repair loops.

::: tip Sandbox capabilities
`sema/check-string` works in memory and requires no capability.
`sema/check-file` requires `fs-read` in a sandboxed run and returns
`PermissionDenied` when it is denied. See the
[CLI sandbox documentation](/docs/cli#sandbox).
:::

```sema
(read/string "(+ 1 2)")            ; => the form (+ 1 2)
(read/all "(a) (b)")               ; => ((a) (b))
(format/form '(define  x  1))      ; => "(define x 1)"

(sema/check-string "(+ 1 2")       ; => {:ok #f :diagnostics [{:level :error
                                   ;        :code "syntax" :message ...
                                   ;        :span {:line :col :end-line :end-col}}]}
(sema/check-file "workflow.sema")  ; same, reading a file
```
