There are many kinds of confidence intervals for binomial proportions.
The Wikipedia article on this topic, discusses some of them.
Some of the kinds of confidence intervals do not work well with data that show sample proportions near $0$ or $1.$ Especially if you have such
sample results, you need to avoid types of intervals that give error messages,
non-answers, or absurd answers.
Wald intervals. These are 'asymptotic' intervals based on assumptions that are strictly true only as $n$ approaches $\infty$ and so they do not work well for small $n.$ In particular if the sample proportion is near $0$ or $1$ they may have "nonsense" boundaries that lie outside $[0,1].$
For example: if we have $x = 39$ successes in $n = 40$ trials, the
point estimate of $p$ is $\hat p = x/n = 39/40 = 0.975$ and the 95% Wald interval is $\hat p \pm 1.96 \sqrt{\frac{\hat p(1-\hat p)}{n}}.$ which computes to
$(0.927, 1.023).$ [Computation below in R.] Also, in case $x = n = 40$ you can check that the Wald interval is of zero length, as if to 'guarantee' that $p=1,$ which is inappropriate.
p.est = 39/40
CI = p.est + qnorm(c(.025,.975))*sqrt(p.est*(1-p.est)/40); CI
[1] 0.9266173 1.0233827
Jeffries intervals. These are based on a Bayesian argument that begins with the non-informative prior distribution $\mathsf{Beta}(.5, .5).$ This guarantees that the result, treated as a frequentist confidence interval,
can never have endpoints outside the unit interval. [Even though this interval estimate has a Bayesian 'heritage', the Wikipedia article says that it has excellent properties when used as a frequentist CI; this claim matches my own personal experience.]
A 95% Jeffries CI
for data $x = n = 40$ uses quantiles $.025$ and $.975$ of the distribution
$\mathsf{Beta}(.5+x,\, .5+n-x),$ so that the interval computes to
$(0.9395, 0.99999).$
qbeta(c(.025,.975), 40.5, .5)
[1] 0.9395020 0.9999878
Clopper-Pearson intervals. The R procedure binom.test
gives an 'exact' confidence interval. [The interval is called exact because it relies on binomial CDFs, avoiding normal and other approximations. Its somewhat messy formula is shown in the Wikipedia link.]
For $x = 39, n = 40$ the resulting 95% CI amounts to $(0.8684, 0.9994),$
as shown below. For $x = n = 40,$ the 95% CI is $(0.9119, 1.0000),$
essentially a one-sided CI [computation not shown].
binom.test(39,40)$conf.int
[1] 0.8684141 0.9993673
attr(,"conf.level")
[1] 0.95
Note: For about the last 25 years an Agresti-Coull modification
of the Wald interval has been recommended. In order to emulate
other more accurate kinds of CIs, it artificially appends 2 successes and two failures to the data and then uses the formula for the Wald interval.
In many cases this interval does give more
accurate results than the Wald interval. However, for sample
proportions at or near $0$ or $1,$ Agresti-Coull intervals can
still produce bounds outside of the unit interval.
I mention this style of interval because it is frequently used and I suspect
it may be giving the results you show in your answer.
Without an actual numerical example, one can only speculate.