-
Notifications
You must be signed in to change notification settings - Fork 0
feat(method): refuse prompt boilerplate as unique content #152
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
248c555
feat(method): refuse prompt boilerplate as unique content
seonghobae 6a61818
Merge remote-tracking branch 'origin/main' into review/pr152-current
seonghobae 5319e0c
fix(prompt-source): apply repository rustfmt
seonghobae c5fb37d
test(quality): derive docstring crate count from workspace contract
seonghobae 9409d83
docs: remove duplicate provider payload ledger row
seonghobae a67d903
docs(prompt): bound identity claim to repository policy
seonghobae 601e402
Merge current main into prompt source gate
seonghobae 70a6c66
docs: narrow prompt identity evidence claims
seonghobae 59ed57c
Merge remote-tracking branch 'origin/main' into agent/prompt-source
seonghobae c1bd092
chore: regenerate Cargo.lock after main merge
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "prompt_source" | ||
| description = "Prompt boilerplate is not unique content and not stopword deletion." | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| authors.workspace = true | ||
| repository.workspace = true | ||
| homepage.workspace = true | ||
| readme.workspace = true | ||
| keywords.workspace = true | ||
| categories.workspace = true | ||
| publish = false | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //! Fail-closed prompt-source errors. | ||
|
|
||
| use std::fmt; | ||
|
|
||
| /// A fail-closed prompt-source error. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| #[non_exhaustive] | ||
| pub enum PromptSourceError { | ||
| /// Prompt boilerplate was treated as unique latent content. | ||
| PromptIsNotUniqueContent, | ||
| /// Prompt boilerplate was treated as stopword deletion. | ||
| PromptIsNotStopwordDeletion, | ||
| /// A recovery slice was empty or length-mismatched. | ||
| InvalidPromptPayload, | ||
| } | ||
|
|
||
| impl fmt::Display for PromptSourceError { | ||
| fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| let message = match self { | ||
| Self::PromptIsNotUniqueContent => "prompt boilerplate is not unique latent content", | ||
| Self::PromptIsNotStopwordDeletion => "prompt boilerplate is not stopword deletion", | ||
| Self::InvalidPromptPayload => "invalid prompt-source payload", | ||
| }; | ||
| formatter.write_str(message) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for PromptSourceError {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::PromptSourceError; | ||
|
|
||
| #[test] | ||
| fn error_messages_are_stable() { | ||
| for (error, message) in [ | ||
| ( | ||
| PromptSourceError::PromptIsNotUniqueContent, | ||
| "prompt boilerplate is not unique latent content", | ||
| ), | ||
| ( | ||
| PromptSourceError::PromptIsNotStopwordDeletion, | ||
| "prompt boilerplate is not stopword deletion", | ||
| ), | ||
| ( | ||
| PromptSourceError::InvalidPromptPayload, | ||
| "invalid prompt-source payload", | ||
| ), | ||
| ] { | ||
| assert_eq!(error.to_string(), message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| //! Prompt boilerplate versus unique latent content. | ||
|
|
||
| use crate::PromptSourceError; | ||
|
|
||
| /// Closed vocabulary of prompt-related token treatments. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum PromptKind { | ||
| /// Instruction or prompt boilerplate, not unique document meaning. | ||
| PromptBoilerplate, | ||
| /// Token treatment reserved for unique latent content. | ||
| UniqueContent, | ||
| } | ||
|
|
||
| impl PromptKind { | ||
| /// Return the stable wire kind name. | ||
| #[must_use] | ||
| pub const fn wire_name(self) -> &'static str { | ||
| match self { | ||
| Self::PromptBoilerplate => "prompt_boilerplate", | ||
| Self::UniqueContent => "unique_content", | ||
| } | ||
| } | ||
|
|
||
| /// Parse a stable wire kind name. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`PromptSourceError::InvalidPromptPayload`] for unrecognized | ||
| /// names. | ||
| pub fn from_wire_name(name: &str) -> Result<Self, PromptSourceError> { | ||
| match name { | ||
| "prompt_boilerplate" => Ok(Self::PromptBoilerplate), | ||
| "unique_content" => Ok(Self::UniqueContent), | ||
| _ => Err(PromptSourceError::InvalidPromptPayload), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Refuse to treat prompt boilerplate as unique latent content. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`PromptSourceError::PromptIsNotUniqueContent`] when `kind` is | ||
| /// [`PromptKind::PromptBoilerplate`]. | ||
| pub fn refuse_prompt_as_unique_content(kind: PromptKind) -> Result<(), PromptSourceError> { | ||
| match kind { | ||
| PromptKind::PromptBoilerplate => Err(PromptSourceError::PromptIsNotUniqueContent), | ||
| PromptKind::UniqueContent => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Refuse to treat prompt boilerplate as stopword deletion. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`PromptSourceError::PromptIsNotStopwordDeletion`] when `kind` is | ||
| /// [`PromptKind::PromptBoilerplate`]. | ||
| pub fn refuse_prompt_as_stopword_deletion(kind: PromptKind) -> Result<(), PromptSourceError> { | ||
| match kind { | ||
| PromptKind::PromptBoilerplate => Err(PromptSourceError::PromptIsNotStopwordDeletion), | ||
| PromptKind::UniqueContent => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Fraction of recovered prompt kinds that match known truth. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`PromptSourceError::InvalidPromptPayload`] when either slice is | ||
| /// empty or the lengths differ. | ||
| pub fn identity_recovery_rate( | ||
| truth: &[PromptKind], | ||
| decided: &[PromptKind], | ||
| ) -> Result<f64, PromptSourceError> { | ||
| if truth.is_empty() || truth.len() != decided.len() { | ||
| return Err(PromptSourceError::InvalidPromptPayload); | ||
| } | ||
| let mut matches = 0_u32; | ||
| for (truth_kind, decided_kind) in truth.iter().zip(decided) { | ||
| if truth_kind == decided_kind { | ||
| matches += 1; | ||
| } | ||
| } | ||
| Ok(f64::from(matches) / truth.len() as f64) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::{ | ||
| PromptKind, identity_recovery_rate, refuse_prompt_as_stopword_deletion, | ||
| refuse_prompt_as_unique_content, | ||
| }; | ||
| use crate::PromptSourceError; | ||
|
|
||
| #[test] | ||
| fn local_branches_cover_kinds_payloads_and_wire_names() { | ||
| assert_eq!( | ||
| refuse_prompt_as_unique_content(PromptKind::PromptBoilerplate), | ||
| Err(PromptSourceError::PromptIsNotUniqueContent) | ||
| ); | ||
| assert_eq!( | ||
| refuse_prompt_as_stopword_deletion(PromptKind::PromptBoilerplate), | ||
| Err(PromptSourceError::PromptIsNotStopwordDeletion) | ||
| ); | ||
| refuse_prompt_as_unique_content(PromptKind::UniqueContent).expect("unique"); | ||
| refuse_prompt_as_stopword_deletion(PromptKind::UniqueContent).expect("unique"); | ||
| for kind in [PromptKind::PromptBoilerplate, PromptKind::UniqueContent] { | ||
| assert_eq!( | ||
| PromptKind::from_wire_name(kind.wire_name()).expect("round-trip"), | ||
| kind | ||
| ); | ||
| } | ||
| assert_eq!( | ||
| PromptKind::from_wire_name("template"), | ||
| Err(PromptSourceError::InvalidPromptPayload) | ||
| ); | ||
| let matched = identity_recovery_rate( | ||
| &[PromptKind::PromptBoilerplate], | ||
| &[PromptKind::PromptBoilerplate], | ||
| ) | ||
| .expect("rate"); | ||
| assert!((matched - 1.0).abs() < f64::EPSILON); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[], &[]), | ||
| Err(PromptSourceError::InvalidPromptPayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[PromptKind::PromptBoilerplate], &[]), | ||
| Err(PromptSourceError::InvalidPromptPayload) | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #![forbid(unsafe_code)] | ||
| #![deny(missing_docs)] | ||
| #![allow(clippy::cast_precision_loss)] | ||
| //! Prompt boilerplate is not unique latent content. | ||
| //! | ||
| //! Instruction and prompt text stays explicit method structure. It is not | ||
| //! unique document meaning and is not erased by a stopword list | ||
| //! (ADR 0004/0012). | ||
|
|
||
| mod error; | ||
| mod kind; | ||
|
|
||
| /// Fail-closed prompt-source errors. | ||
| pub use error::PromptSourceError; | ||
| /// Closed vocabulary of prompt-related token treatments. | ||
| pub use kind::PromptKind; | ||
| /// Fraction of recovered prompt kinds that match known truth. | ||
| pub use kind::identity_recovery_rate; | ||
| /// Refuse to treat prompt boilerplate as stopword deletion. | ||
| pub use kind::refuse_prompt_as_stopword_deletion; | ||
| /// Refuse to treat prompt boilerplate as unique latent content. | ||
| pub use kind::refuse_prompt_as_unique_content; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //! Integration contract for the `prompt_source` package identity. | ||
|
|
||
| #[test] | ||
| fn package_identity_is_stable() { | ||
| let observed = std::hint::black_box(env!("CARGO_PKG_NAME")); | ||
| assert_eq!(observed, "prompt_source"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //! Prompt boilerplate is not unique content and not stopword deletion. | ||
|
|
||
| use prompt_source::{ | ||
| PromptKind, PromptSourceError, identity_recovery_rate, refuse_prompt_as_stopword_deletion, | ||
| refuse_prompt_as_unique_content, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn prompt_boilerplate_cannot_become_unique_content_or_stopword_deletion() { | ||
| assert_eq!( | ||
| refuse_prompt_as_unique_content(PromptKind::PromptBoilerplate), | ||
| Err(PromptSourceError::PromptIsNotUniqueContent) | ||
| ); | ||
| assert_eq!( | ||
| refuse_prompt_as_stopword_deletion(PromptKind::PromptBoilerplate), | ||
| Err(PromptSourceError::PromptIsNotStopwordDeletion) | ||
| ); | ||
| refuse_prompt_as_unique_content(PromptKind::UniqueContent).expect("unique"); | ||
| refuse_prompt_as_stopword_deletion(PromptKind::UniqueContent).expect("unique"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn recovered_kinds_match_known_truth_better_than_a_unique_content_collapse() { | ||
| let truth = [ | ||
| PromptKind::PromptBoilerplate, | ||
| PromptKind::UniqueContent, | ||
| PromptKind::PromptBoilerplate, | ||
| ]; | ||
| let recovered = truth; | ||
| let collapsed = [ | ||
| PromptKind::UniqueContent, | ||
| PromptKind::UniqueContent, | ||
| PromptKind::UniqueContent, | ||
| ]; | ||
| let recovered_rate = identity_recovery_rate(&truth, &recovered).expect("recovered"); | ||
| let collapsed_rate = identity_recovery_rate(&truth, &collapsed).expect("collapsed"); | ||
| let expected = { | ||
| let mut matches = 0_u32; | ||
| for (truth_kind, decided_kind) in truth.iter().zip(recovered.iter()) { | ||
| if truth_kind == decided_kind { | ||
| matches += 1; | ||
| } | ||
| } | ||
| f64::from(matches) / f64::from(u32::try_from(truth.len()).expect("len")) | ||
| }; | ||
| assert!((recovered_rate - expected).abs() < f64::EPSILON); | ||
| assert!(recovered_rate > collapsed_rate); | ||
| } | ||
|
|
||
| #[test] | ||
| fn empty_or_mismatched_kind_payloads_fail_closed() { | ||
| assert_eq!( | ||
| identity_recovery_rate(&[], &[]), | ||
| Err(PromptSourceError::InvalidPromptPayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[PromptKind::PromptBoilerplate], &[]), | ||
| Err(PromptSourceError::InvalidPromptPayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate( | ||
| &[PromptKind::PromptBoilerplate, PromptKind::UniqueContent], | ||
| &[PromptKind::PromptBoilerplate] | ||
| ), | ||
| Err(PromptSourceError::InvalidPromptPayload) | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
docs/adr/0012-temporal-relational-shared-latent-topic-measurement.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: prompt_source recovery/refusal logic verified correct
The new crate's core logic in kind.rs was reviewed carefully.
identity_recovery_ratefails closed on empty or length-mismatched slices (kind.rs), counts matches over the zipped pairs, and divides bytruth.len()(safe since non-empty). Thefrom_wire_name/wire_nameround-trip and the two refusal functions are exhaustive over the closedPromptKindvocabulary. No correctness issues found here.Was this helpful? React with 👍 or 👎 to provide feedback.