Belief engineering and code provenance
Can a system prompt that installs a worldview act like a distinct code author? Eight generated programs, two such authors, and a stylometry harness were used to explore how reliably authorship can be attributed and how large a foreign block of code must be before it is detected.
What was tested
In the experiment, belief engineering refers to writing a system prompt that gives a model a complete worldview, a professional identity, or both, so that its output reflects that stance without being told which style to use. Two families of such prompts were used. In the first, two opposing philosophies of software (an emergent, domain-modelling holist and a reductionist, data-first empiricist) were stated as beliefs. In the second, two professional identities (a principal architect at a regulated firm and a scrappy startup data hacker) were given, each with a different client.
Every prompt asked for the same program: identify companies within thematic communities that are likely to be successful, innovative and disruptive. The task content was therefore constant, and any systematic difference in the code could be attributed to the persona.
Two questions were then asked of the resulting code. Attribution: can the persona that wrote a function be recovered from style alone? Provenance injection: if a block of functions from the opposite persona is spliced into a file, can a detector built from that file’s own functions flag it, without flagging other files by the same persona?
Background. The framing of prompts as belief systems was set out in an earlier essay, Prompt Engineering as Belief Engineering: How Identity Constraints Guide AI Outputs (Medium, May 2025), which argues that role and identity prompts narrow the range of outputs a model is likely to produce. The experiment below tests one consequence of that idea on code.
Method, step by step
The pipeline parses code with Python’s ast module and never executes it. Select a step, or use the buttons to advance.
The four personas
Authors were defined by system prompt alone. Author A comprises the holist prompt and the enterprise-architect prompt (one file from the first, three trials from the second). Author B comprises the empiricist prompt and the startup-hacker prompt, in the same proportions. Prompts are reproduced in full and unedited.
Attribution
A classifier was trained on function-level features and evaluated with leave-one-file-out cross-validation: the model never saw any function from the file being scored. This prevents file-specific vocabulary from leaking between training and test data.
| Classifier | Function balanced accuracy | Files correct | Function confusion |
|---|---|---|---|
| Logistic regression | 0.963 | 8 / 8 | A: 114 of 114 correct. B: 37 of 40 correct. |
| Random forest | 0.875 to 0.958 | 7 / 8 to 8 / 8 | Varies with library version and seed; the 0.958 run gave A: 113 of 114, B: 37 of 40. |
| Nearest neighbour (file level) | — | 8 / 8 | Between-author distance 2.49× the within-author distance. |
The corpus, file by file
Functions of at least three lines were included. The table is ordered by author.
| File | Author | Prompt | Lines | Functions | Classes | Mean function length |
|---|---|---|---|---|---|---|
alpha_solution | A | Alpha | 733 | 35 | 25 | 8.7 |
enterprise_trial1 | A | Enterprise | 978 | 28 | 26 | 17.6 |
enterprise_trial2 | A | Enterprise | 752 | 26 | 19 | 14.8 |
enterprise_trial3 | A | Enterprise | 788 | 25 | 21 | 15.0 |
omega_solution | B | Omega | 258 | 11 | 0 | 17.2 |
startup_trial1 | B | Startup | 213 | 11 | 0 | 14.0 |
startup_trial2 | B | Startup | 186 | 10 | 0 | 12.1 |
startup_trial3 | B | Startup | 163 | 8 | 0 | 11.2 |
Mean function length alone does not separate the authors (author B’s empiricist file averages 17.2 lines, longer than two of author A’s files). The separation comes from the combination of features, in particular the structure of the syntax tree inside each function, which is why simple summary statistics were insufficient and AST-path features were added.
Detection power versus insertion size
For each host file, a model of “normal” was built from that file’s own functions only. A probe block of k functions was then scored by the distance of its average feature vector from the host centroid. Foreign blocks came from the opposite author; native blocks came from other files by the host’s own author. ROC-AUC measures how well the score separates the two: 0.5 is chance and 1.0 is perfect separation. Each point is a mean over eight hosts, with the band showing ± one standard deviation across hosts.
| Insertion size (functions) | Mean ROC-AUC | sd across hosts | Interpretation |
|---|
A plausible explanation for the size effect
One reading of the curve, not tested directly here: a block drawn from the host’s own author averages toward the host centroid, because the idiosyncrasies of individual functions cancel. A block from a different author carries a persistent structural bias that does not cancel as functions are added. On that reading, the signal grows with block size while the noise shrinks, so detection power would depend on the size of the contested region rather than on any single function.
Preliminary observations
- A worldview in a system prompt appears to act as an author. In this corpus, four prompts built from two construction styles produced code that a linear classifier separated almost perfectly, with held-out files never seen in training. With two authors and one task, this is a suggestive result, not a general one.
- The signal appears to be structural and aggregate. Attribution of a single function is noisy (single-function injection reached 0.70), but evidence accumulated quickly: five functions reached 0.93 and twelve reached 0.996.
- Syntax-tree paths appeared to carry the result. Eleven conventional style features (length, nesting, comment density, annotations, identifier length and similar) were not enough to detect a single foreign function. Adding node-type counts and parent-to-child edge counts from the syntax tree (330 of the 341 features) moved single-function detection from near chance to 0.70 (a feature ablation on one small corpus).
- The false-positive control matters as much as the detection. The native comparison set used other files by the same author, so a detector that merely recognised “different file” would score at chance. The reported AUCs measure author difference, not file difference.
- A hypothesis for auditing: the unit of analysis should be the region, not the line. If the pattern holds on larger data, a reviewer or tool trying to establish whether a codebase mixes provenance sources should score contiguous blocks of several functions and report confidence as a function of block size.
Limits of the evidence
- The authors are personas of one base model. They differ in instruction, not in training. Real-world authors differ in many more ways, so detection in practice is plausibly easier, though this was not measured here.
- The corpus is small. 154 functions, 8 files, 2 authors, and one task. The standard deviations across hosts (0.09 to 0.12 at small sizes) reflect that.
- Authors were pooled by induced structure. The grouping of holist with enterprise and empiricist with startup follows the observed class-based versus flat structure; a different grouping was not tested.
- The random forest was unstable. Its accuracy differed between two runs (0.875 and 0.958), which indicates that comparisons between classifiers are not reliable at this sample size.
- No significance testing or confidence intervals beyond the spread across hosts were computed.
- The detector is deliberately simple. A one-class centroid distance on standardised features was used. Stronger detectors were not evaluated, so the curve is a lower bound for this feature set rather than a ceiling.
- Splicing was synthetic. Foreign blocks were drawn from other files rather than inserted and reconciled by a developer, so integration effects such as renamed variables or harmonised formatting were not represented.
- Python only. Parsing, features and results are specific to Python syntax trees.
What would make this solid
Replication is needed before these figures are treated as findings. The natural extensions are more authors and tasks, a second language, real developer-edited insertions, and stronger detectors evaluated against the same curve. The measurement scripts and results file are retained so that any extension can be compared to the baseline reported here.